‎2008 Jan 02 1:34 PM
As all components of a class moved to an Interface are all made PUBLIC is there actually ANY point in ever using Interfaces.
Since a good implementation of a Class will have most of its methods and attributes defined as PRIVATE or PROTECTED there really IMO seems no point in using the whole Interface concept or have I actually missed something here.
I was trying to tidy up several classes by using a common Interface --but I really want most of the methods and attributes to be PRIVATE with a small PUBLIC section available to "the Outside".
Cheers
jimbo
‎2008 Jan 02 2:29 PM
As all components of a class moved to an Interface are all made PUBLIC is there actually ANY point in ever using Interfaces.
The whole point of interfaces is to be ABSTRACT and PUBLIC, otherwise they would make little sence.
Since a good implementation of a Class will have most of its methods and attributes defined as PRIVATE or PROTECTED there really IMO seems no point in using the whole Interface concept or have I actually missed something here.
It really depends on how you use (or understand) object-oriented designs. A "good implementation" of a class will inlcude only PRIVATE or PROTECTED attributes or at most PUBLIC READ-ONLY attributes (and only for performance reasons, i.e. microseconds). You can sure define publc methods if you want.
The goal of an interface is (as you suggested) to show a certain functionality to the rest of the world. A class can implement many interfaces and a client, which is holding a reference to the interface, can access only the methods defined by this interface! The class can sure have other methods (own) or exposed by other interfaces and these can be public (or otherwise) as well.
Also as a rule of the thumb, one should program to an interface and to an implementation - as described 12 years ago by GoF (see http://en.wikipedia.org/wiki/Design_Patterns)
I guess, that google has a lot of examples of why to use interfaces and what are their advantages. Try a search.
‎2008 Jan 02 8:27 PM
Hello James
If you have a SAP system available with RE-FX then have a look at class CL_RECN_CONTRACT (Real Estate Contract).
This class implements the interfaces IF_RECA_STORABLE and IF_RECA_BUS_OBJECT (besides many others).
A contract consists of many objects:
- the contract itself (CL_RECN_CONTRACT)
- conditions
- rental objects
- etc...
When you update a contract all contained parts of the contract have to be updated as well. All sub-objects of the contract implement the interface IF_RECA_STORABLE as well.
When you save the contract the method IF_RECA_STORABLE~STORE (implemented within class CL_RECN_CONTRACT) will be called.
To save the rental objects of the contract the method IF_RECA_STORABLE~STORE (implemented within class CL_REBD_RENTAL_OBJECT) will be called.
Assuming that the conditions are implemented by class CL_RECN_CONDITION_MNGR_CN you may guess yourself which interface method is called when the conditions are saved!.
I once debugged the saving of a RE-FX contract and I passed many times the STORE method call yet due to the polymorphism (by using interfaces) every time a different part of the contract was saved.
Kind Regards,
Uwe