As you’d expect, classes are used to represent objects, abstractions and interfaces. Relationships between classes are used to represent relationships between objects or abstractions. The most important relationships between classes are:
• uses-a: if class A ‘uses-a’ class B, then A has a member of type B, B&, const B&, B* or const B*, or a function that can easily return a B in one of these guises; A can then use B’s member functions and data.
• has-a: ‘has-a’ is like ‘uses-a’, except that A takes responsibility for constructing and destroying the B as well as using it during its lifetime
• is-a: ifclass A ‘is-a’ class B, then B should be an abstraction of A; ‘is-a’ relationships are usually represented in C++ using public derivation
• implements: if class A implements an interface M, then it implements all M’s pure virtual functions; this is the only circumstance in which multiple inheritance is used in Symbian OS.
面向对象中,类与类之间的关系有些是不好把握的,《Symbian OS C++ for Mobile Phones Volume 3》书中的观点能有些启发吧!
本文详细阐述了面向对象编程中类与类之间的四种关键关系:使用关系(uses-a)、包含关系(has-a)、继承关系(is-a)及实现关系(implements)。通过这些关系,可以更好地理解和设计复杂的软件系统。

1356

被折叠的 条评论
为什么被折叠?



