Solved

Inheritance

Posted on 2008-06-24
4
424 Views
Last Modified: 2013-11-26
HI Experts

We have a .NET application (VS 2008) that uses the Factory and Command Patterns to generate & invoke commands. Commands are logged, may have or not have timer support and are classified to categories which are also hierarchical (i.e. in category A you have commannd A1 and command A11 that is inherited from command A1 and so on...)

The difficulty with this is debug, since there are about 7 levels in the hierarchy , it takes time to navigate   and find the problem origin.

Questions :

1) When I did OO courses, I remember that they strongly recommended not to pass the 3 object hierarchy depth , is that true?

2) What design alternatives can you recommend in order to make our commands hierarchy shorter ?

Thanks
cmd.JPG
0
Comment
Question by:elimesika
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:mastoo
Comment Utility
1) One of my favorite books:
  "Heuristic 5.4 In theroy, inheritance hierarchies should be deep - the deeper, the better.
  Heruistic 5.5 In practice, inheritance hierarchies should be no deeper than an average person can keep in his or her short-term memory.  A popular value for this depth is six."  I must be more feeble minded than most as I like 3.

2) I can't read the jpg but it looks like you might be suffering a class explosion.  The command pattern purpose is to encapsulate requests, hiding implementation from the caller.  Possibly a narrower command hierarchy using classes representing individual functionality within a command and then aggregating functionality via Mediator pattern.
0
 
LVL 19

Author Comment

by:elimesika
Comment Utility
HI

Thanks for your respond.
Given that all commands are isolated and have no commnad-to-command commun ication, it seems that the mediator pattern will not help to simplify this.

Is there a way to use interfaces when applicable instead of classes in the inheritance tree to shorten the depth of the inheritance tree ???

0
 
LVL 21

Accepted Solution

by:
mastoo earned 500 total points
Comment Utility
I meant that you'd have a smaller number of command classes, and when they are constructed they get different components added.  I was thinking the mediator within the command would orchestrate those pieces, but on second thought that would be overkill.

For instance, during construction the factory feeds the command constructor a CLogger.  CLogger might be a base class reference to a CLogPrinter or CLogFile.  I'm not sure if this example applies to your case but it would be one less dimension for the command hierarchy and it helps with another golden rule: A class should capture one and only one key abstraction (i.e., a command shouldn't have to worry about implementation of logging).
0
 
LVL 19

Author Closing Comment

by:elimesika
Comment Utility
Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now