Posted on 2008-06-24
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 ?

Question by:elimesika
  • 2
  • 2
LVL 21

Expert Comment

ID: 21866714
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.
LVL 19

Author Comment

ID: 21868871

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 ???

LVL 21

Accepted Solution

mastoo earned 500 total points
ID: 21869841
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).
LVL 19

Author Closing Comment

ID: 31470387

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 80
Authentication of Web Services 3 53
Replace &lt; with < 14 56
C# guarantee sql connection close 6 30
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

895 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

18 Experts available now in Live!

Get 1:1 Help Now