2013 Sep 02 10:07 AM
Hi friends,
In my project I have one interface say IF_POST_ACCESS, which has methods READ, MODIFY, DELETE, SEARCH defined.
In its implementation class CL_POST_ACCESS_IMPL, the implementation for READ, MODIFY AND DELETE are very simple with just several lines for each. However the implementation for SEARCH is not trivial. It contains about 160 lines. I split the code into 4 seperately methods so the implementation for SEARCH looks like below:
init_for_search();
do_search();
post_search();
cleanup();
Now CL_POST_ACCESS_IMPL has totally 7 methods, 3 public from interface and the 4 private. Let me call it design A.
my concern is the new created 4 private methods are just serving for SEARCH, they have nothing to do with READ, MODIFY and DELETE and thus should not appear in class CL_POST_ACCESS_IMPL. As a result, I have design B: create a new local class LCL_POST_SEARCH_EXECUTOR and put all 4 private methods into it. In SEARCH implementation, just delegate the call to the local class. So in design B the global class only contains 4 methods defined in interface, which looks very clean.
Would you please kindly share your suggestion which design is better from your side? Thanks a lot!
Best regards,
Jerry
2013 Sep 02 10:54 AM
Hi Jerry,
Your design of classes is absolutely right.wasting the single method for searching.it is better to design the separate class for these methods
Regards
Khaleel
2013 Sep 02 10:54 AM
Hi Jerry,
Your design of classes is absolutely right.wasting the single method for searching.it is better to design the separate class for these methods
Regards
Khaleel
2013 Sep 02 12:02 PM
Even thought you split the logic into 4 new private methods, to me it seems that the logic implementation for SEARCH should still be part of class CL_POST_ACCESS_IMPL. Those new methods may not be related to READ, MODIFY or DELETE, but they are still a process that belongs to CL_POST_ACCESS_IMPL.
Let's say you use the local class. If you ever have to use this class again somewhere else you would have to copy-paste the local class to the other objects in order to use the SEARCH implementation. Using an interface in most cases is enough for delivering different implementations for several classes.
Of course there's a lot to consider, but based on your question I'd go with design A.
Regards