2

How do you explain class hierarchies.

I think my google power has gone down because when i searched for 'Class hierarchies' as the term i got a few examples of how classes are organized and the inheritance relationship between them. Is that all about class hierarchies? How do you explan class hierarchy to a C developer?

Also whats the difference between class hierarchy and object hierarchy?

Actually i am due a presentation on Saturday to my office mates and coming across so many theoretical topics :(

Any help would be appreciated.

Many thanks

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Asif
  • 1,288
  • 1
  • 16
  • 27
  • 2
    "Class" is the definition, the blueprint - the plan; "Object" is the actual instantiation at runtime. So in "design mode", you have class hierarchies. At runtime, you have object hierarchies. – marc_s Jan 14 '11 at 06:19
  • Yes, the class hierarchy is created through layers of inheritance. Why would you be explaining this to a C developer? – Cody Gray - on strike Jan 14 '11 at 06:21
  • Thanks mate. I need to give OO presentation to a bunch of students who know only C. Its tomorrow and i am nervous as we have so many theoretical stuff like hierarchies etc :( – Asif Jan 14 '11 at 06:57

1 Answers1

5

I'll try to answer in a few lines.

A class hierarchy probably refers to the structure composed by classes and inheritance links between them. For example, you may have class Car that inherits from class Vehicle, and so on. That makes up a class hierarchy.

Now, when you create an instance of Car using the new operator, you obtain a Car object; there is no hierarchy involved. That is, there is no "two objects linked together through inhertance" like the two classes are. We can say that, at instantiation time, class hierarchies "get flattened".

The phrase object hierarchies, therefore, often refers to whole/part structures. You may have another class, perhaps named Wheel, plus a reference from Car to Wheel so that cars may contain up to four wheels (imagine an array of wheels in a car object, or any other kind of container if you wish). This arrangement makes up a graph (rather than a hierarchy) of objects ar run time where whole/part (sometimes called "aggregation" or "composition") relationships are the major links.

In summary: class hierarchies and object hierarchies are totally different and not related.

I hope this helps.

CesarGon
  • 15,099
  • 6
  • 57
  • 85
  • 1
    If object hierarchies are not in fact hierarchies why Booch et al. have called them so? Don't you think it sounds a bit strange that class hierarchies "get flattened" at instantiation time and that is how object hierarchy was created? – Timofey Jan 22 '11 at 15:21
  • 1
    @Tim: As I say, "object hierarchies" refer to whole/part structures *often*, not always. I can't know whether this is the case with any particular source without a detailed study. It is quite probable, though, and I don't find it strange at all. Mereological hierarchies are a well-known phenomenon (see http://en.wikipedia.org/wiki/Mereology for background) even though, in practice, they often result in structures that are not strict trees but graphs. – CesarGon Jan 22 '11 at 22:04
  • 1
    @CesarGon: Booch in his work "OOAD with Applications" distinguishes 2 types of hierarchies: "is a" hierarchy that defines relationships between classes and "part of" hierarchy that defines relationships between objects. Are the "part of" hierarchies somehow connected to those which you call "whole/part structures" is not really clear, but Booch does not use a term "whole/part structures" in his work. – Timofey Jan 23 '11 at 17:52
  • 1
    @Tim: Yes, they are connected. The term "whole/part" is a bit more up to date than "part of", and is the one used in current research in conceptual modelling (e.g. works by Henderson-Sellers, Barbier, and even myself). Besides the terminology, the "part of" hierarchies that Booch defines are, as I said earlier, not hierarchies strictly speaking, because they do not conform to a tree structure but to a graph. This is different to "is a" which, in a single-inheritance contexts, are strict tree-like. So I would avoid using the word "hierarchy" here. :-) – CesarGon Jan 23 '11 at 18:01
  • 1
    @CesarGon: Fair enough. Would you recommend some scientific papers or even books written by Henderson-Sellers, Barbier or you in area of conceptual modeling? – Timofey Jan 23 '11 at 18:13
  • 1
    @Tim: If you are interested in whole/part relationships, I can suggest http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=1199074; it contains references to other interesting work. For a broader and less specialised work, see http://portal.acm.org/citation.cfm?id=1563320. You may find copies available on the web; let me know privately if you don't. – CesarGon Jan 23 '11 at 18:21
  • 1
    @Tim: No problem. If you are after a book, chapter 2 and some other sections of http://www.amazon.com/Metamodelling-Software-Engineering-Cesar-Gonzalez-Perez/dp/0470030364/ may be of use to you. – CesarGon Jan 23 '11 at 18:50