2008 Sep 11 4:44 PM
Hi all,
I have the following 'issue': I want to create / update / retrieve BP relationships. My idea is to create a superclass with all general data for a relationship like Partner 1 & 2, type of relationship (employer-employee, husband-wife etc.). So far so good, but now it comes. All relationships have different attributes (created in CRM with Easy Enhancement Workbench, comparable to customer includes).
Does it make sense to create a subclass per relationship type, because based on that different logic has to be processed. Or put all these attributes, whether they belong to relationship type A, or B, in the same superclass?
Normally I would say the second option is better / more logical and put them all in ONE (super)class, but since every relationship is a specialization of the superclass due to all the different attributes, it would also make sense to create a new subclass for every relationship type. I actually want to avoid, using IF statement within the class (IF relationship A, ELSEIF relationship B, etc.), because when creating a new relationship type, I would have to change the superclass over and over again.
<removed_by_moderator> Hope to hear from you.
Any suggestions?
Edited by: Julius Bussche on Sep 12, 2008 10:35 AM
2008 Sep 12 9:51 AM
Hi Micky,
Why do not you define the methods in INTERFACE and implement in the subclasses where ever necessary
with concept of Inheritance..
As you repeatedly change the implementation part of the methods so better define in interface and inherit
the interface from a class and proceed.
Hope this would help you.
Good luck
Narin
Hi all,
I have the following 'issue': I want to create / update / retrieve BP relationships. My idea is to create a superclass with all general data for a relationship like Partner 1 & 2, type of relationship (employer-employee, husband-wife etc.). So far so good, but now it comes. All relationships have different attributes (created in CRM with Easy Enhancement Workbench, comparable to customer includes).
Does it make sense to create a subclass per relationship type, because based on that different logic has to be processed. Or put all these attributes, whether they belong to relationship type A, or B, in the same superclass?
Normally I would say the second option is better / more logical and put them all in ONE (super)class, but since every relationship is a specialization of the superclass due to all the different attributes, it would also make sense to create a new subclass for every relationship type. I actually want to avoid, using IF statement within the class (IF relationship A, ELSEIF relationship B, etc.), because when creating a new relationship type, I would have to change the superclass over and over again.
<removed_by_moderator> Hope to hear from you.
Any suggestions?
Edited by: Julius Bussche on Sep 12, 2008 10:35 AM
2008 Sep 12 9:51 AM
Hi Micky,
Why do not you define the methods in INTERFACE and implement in the subclasses where ever necessary
with concept of Inheritance..
As you repeatedly change the implementation part of the methods so better define in interface and inherit
the interface from a class and proceed.
Hope this would help you.
Good luck
Narin
2009 Nov 17 8:08 AM
This question has become very much alive again.
Is this really the way to go, creating an interface? Any other alternatives?
2009 Nov 17 2:51 PM
It looks like you want to implement the Open Closed Principle. You can try using the Interface or Abstract Super Class.
When using the Abstract Super Class, you need to create the Factory method, which can give back you the object reference of your required relationship. So, when ever you introduce a new relationship, you can change this method, or make the implementation of the Factory method dynamic i.e. all subclass for this superclass will have the same prefix with suffix as the relationship name.
You may find these blogs useful:
/people/naimesh.patel/blog/2009/05/20/object-oriented-design-principles-oodp-open-closed-principleocp
/people/naimesh.patel/blog/2009/05/26/object-oriented-design-principles-oodp-ocp-with-business-scenario
Regards,
Naimesh Patel
2009 Nov 18 10:42 AM
Naimesh,
really sounds like something I could definitely use for my 'problem'. Pnts. rewarded, although not yet fully implemented since we are only in design phase. But I will try and do it like this. I already read your blogs in the past, but totally forgot about it (shame on me). Thanks for reminding me.
Gr. Micky.
2009 Nov 18 11:23 AM
Halo Micky,
I suggest you maintain a seperate hierarchy of classes for Instantiation. ie a super class ZCL_FACTORY( which can be abstract or non abstract ) . Whenever you want an object you just ask the factory class to deliver the object .
ie if you have a new subclass relationship type . you add one more method to the ZCL_FACTORY. By that way you do not have to do the IF ...ELSEIF statements .More Clients can actually use this factory to deliver them the required objects.
Moreover make this ZCL_FACTORY non parameterised constructor .By that way you can just create an instance of ZCL_FACTORY initially and pass this instance to the constrcutor of every class that you create.
Regards
Arshad
2009 Nov 18 11:46 AM
Whenever you want an object you just ask the factory class to deliver the object
And what object would that be?
Gr. Micky.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |