THINK!
What do me inherit the Data Class for?
How to operate the db.db?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
THINK!
So do we have to make the Data class implements a interface?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
[SCJP, SCJD]
I think you'll find that Sun anticipates you to declare criteriaFind() an abstract method.
THINK!
In the MVC design pattern there should be three interfaces which are FlyModel, FlyController and FlyView. And we must wirte implementation class for the three interfaces.
And I consider Data class the implementation class of FlyMedel interface.
So I want the Data class to implement a interface to meet the MVC design pattern.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
But I think in the specification of the project, SUN said the data class is complete, so u mustn't modify any existing methods.
Part of your assignment will be to enhance the Data class. You may do this by modification or subclassing, but you should document the approach and reason for your choice.
I also agree that criteriaFind should not be declared abstract. Doing so would force the Data class to be declared abstract which is stoping it from being a "complete" class. Even if you implement a version of criteriaFind in the Data class, a class which extends Data class could always override the criteriaFind method if they wanted a different implementation.
Three classes are in this package: Data, DataInfo, and FieldInfo. With the exception of three methods, noted below, these classes are complete and functional, and you have the source code for them.
[SCJP, SCJD]
I think that the Data class should be designed for extension. I'm guessing you've also kept it's members private. How would you override the criteriaFind() if you do not have access to the file pointer? Searching for records using getRecord(int) is a costly way, creating instances of DataInfo even for records which do not satisfy the criteria. As searching the database in this manner is where the server will spend much of it's time and the number of records could potentially get quite large it may not be feasible.
The way you are suggesting would not make it feasible to alter the behaviour of that method. Are you suggesting that we should only be able to query the database using exact match querys?
From a different angle, the requirements specifices that the user-interface should be desgined with the expectation of future functionality enhancements. Surely these functionality enhancements may wish to query the database in increasingly complex ways?
It is my opinion that Data should be abstract to enable subclasses to define specific query languages.
these classes are complete and functional
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
It is possible to use getRecord(int) to do the searching. And it might actually be better to do that in a large database than to use the readRecord() method which I think you are suggesting? readRecord() has no knowledge of what record it is currently pointing at - it just reads the current record.
Therefore the entire criteriaFind() method would have to be synchronized to ensure that the record pointer is not moved by any other methods. This means that the criteriaFind method becomes a potential bottleneck.
Also, if modifications are required in the future, and we decided that we needed a new version of criteriaFind (or any other method), and we decided that it should use the low level readRecord() method, then I would prefer to change the access on the Data class at that time to give them package level access. That way I could extend the class, while no current classes using Data would be affected.
The problem here is an assumption about what might be required in the future. Now if a later change was to allow partial matches on fields, then perhaps we could do it by creating an overloaded criteriaFind within the Data class itself. Why does it have to be in an extended class?
Sure. But does that mean that for each enhancement you create a new extended class? Or that you enhance an existing class?
I cannot see how implementing criteriaFind() inside the Data class precludes later enhancements, or that making Data class abstract makes it easier to enhance later.
What happens if there are existing applications that are using Data class? We have not been told that there are no other applications - there could be a reporting application and a bulk data entry program already written. Since we have been given a database that already contains records, it is quite likely that there is at least one other application out there than can access the database, possibly through the use of the Data class. You will have just broken that other application.
Making Data class abstract stops it from being functional.
[SCJP, SCJD]
Andrew: Therefore the entire criteriaFind() method would have to be synchronized to ensure that the record pointer is not moved by any other methods. This means that the criteriaFind method becomes a potential bottleneck.
Patrick: I personally have synchronized the whole method because i think that each client might as well get it's query done in one go rather than being interrupted inbetween.
Andrew: The problem here is an assumption about what might be required in the future. Now if a later change was to allow partial matches on fields, then perhaps we could do it by creating an overloaded criteriaFind within the Data class itself. Why does it have to be in an extended class?
Patrick: No comment here except that this a violation of OCP.
You discuss breaking clients. But by extending an existing class you will be breaking the existing contract and hence break clients which depended on that contract.
Andrew: What happens if there are existing applications that are using Data class? We have not been told that there are no other applications - there could be a reporting application and a bulk data entry program already written. Since we have been given a database that already contains records, it is quite likely that there is at least one other application out there than can access the database, possibly through the use of the Data class. You will have just broken that other application.
Patrick: .. Not if the contract on Data is loosening as explained just now.
You explain that the requirements specifies that the Data class is already fully functional and that making it abstract prevents it from being fully funtional. Why then does is it also mention that we can implement criteriaFind() by modification(in the Data class) or by extension(in sublasses)?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|