The Relationships Between Classes in Symbian OS C++ for Mobile Phones Volume 3

来源:互联网 发布:广州数据恢复公司哪家好 编辑:程序博客网 时间:2024/06/06 03:06

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》书中的观点能有些启发吧!