Is it possible that I add more interface functions on Data.java which
is given to my assignment for data access class
SCJP, OCMJD, OCMJEA
42
Originally posted by Jeroen T Wenting:
Correct. What I've done is extend the DB interface with some utility methods and writing some proxies around it.
then you aren't complying with the contract of the interface
SCJP, OCMJD, OCMJEA
Originally posted by Oricio Ocle:
There is no requirement stating the interface must be used by the client.
Only subjetive minds.
A recommended lecture:
3 vs 2 tier
Regards
There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software interacts. Each group should be able to write their code without any knowledge of how the other group's code is written. Generally speaking, interfaces are such contracts
Originally posted by Oricio Ocle:
A recommended lecture:
3 vs 2 tier
Regards
When the interface says: this method performs in such a way, then it darn well better perform in that way. that's all I'm saying.
sorry, but I don't really see how that applies. I have no issue with either a 3 or 2 tier system. And I have no issue with adding additional methods or additional interfaces to the Data object....
Think of it this way: you can create an instance of Data in each of the following ways:
1. public DBMain database = new Data();
2. public Data database = new Data();
If you're code will not work correctly using the first, but rather requires the second to work correctly...
SCJP, OCMJD, OCMJEA
Originally posted by Oricio Ocle:
If Data class implements the interface the requirement is fulfilled, does not matter if data clients interact through the interface or directly to the implementation, IMO.
SCJP, OCMJD, OCMJEA
SCJP, OCMJD, OCMJEA
Originally posted by Oricio Ocle:
Ok, here is an example.
Provided interface: DBMain
Requiered implementation: Data
1)In order to add more funtionality:
In Data.java:
In data clients:
Adam, this client does not work with DBMain, but IMO it fulfills the requirements, since DBMain is implemented, it is waranteed that any other client could use:
Regards
[ August 24, 2006: Message edited by: Oricio Ocle ]
it would NOT work correctly as specified by the DBMain interface, because you need to call additional methods from type Data...
have an object of type DBMain that does not behave like an object of type DBMain...
You don't know that you need to perform some "Extra" operations before you can perform those specified by the interface...
This is the whole purpose of an Interface -> to provide a contract as to how the object behaves, and provide the method signatures used to cause this behavior.
Repeat, interfaces are not used to explain how implementations must be used, the goal of interfaces is explain what clients are expecting to find.You don't know or care about how it's implemented, because the interface is all you need to use it
SCJP, OCMJD, OCMJEA
SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
SCJP, OCMJD, OCMJEA
SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
And you would still get back a valid DBMain object. However, it would NOT work correctly as specified by the DBMain interface, because you need to call additional methods from type Data. So, you have an object of Type DBMain which does not work as you expect it should. Hence, to anybody not are that the object is of type Data (and that's your client, because it thinks it has an object of type DBMain), the object does not work correctly.
This goes beyond the bridge pattern and implementation hiding. This is a matter of "I have an object of type DBMain that does not behave like an object of type DBMain." When all you have is the interface DBMain, and you have NO idea that the type Data exists, then you have to accept the description of the behavior as supplied by DBMain. You don't know that you need to perform some "Extra" operations before you can perform those specified by the interface.
This is the whole purpose of an Interface -> to provide a contract as to how the object behaves, and provide the method signatures used to cause this behavior. You don't know or care about how it's implemented, because the interface is all you need to use it.
Think about it. One of the major goals of Object Orientation is abstraction -> separating implementation from interface. Just give the clients the signatures of the required methods, and tell them how to use them (this is the interface), and keep the implementation hidden -> this way, you can change the implementation later if you need to, and this way, you can re-use the same set of methods in any situation where they apply.
You just need to ensure that the standard methods defined by DBMain interface are not dependant on the helper methods
SCJP, OCMJD, OCMJEA
Not even that it's neccessary.
You just need to ensure that the standard methods defined by DBMain interface are not dependant on the helper methods
SCJP, OCMJD, OCMJEA
You showed up just in time for the waffles! And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|