문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top