next up previous
Next: Relationships within a class Up: Specify Dependencies Previous: Use relationship

Programmed-in relationship

Some relationship cannot be described explicitelly in the programming languages (even not in C++). In such cases the semantic should be implemented by the user code.

In C++ for example there is no language concept to describe inheritance with delegation. In such a case we use other relationship(s), and we program the semantic.

class B
{
    void f();
    void g();
    void h();
};

class A
{
    B *p;
    // ...
    void f();
    void ff();
    void g() { p->g(); }    // delegate g()
    void h() { p->h(); }    // delegate h()
};

A one-to-one mapping between the design concepts and the language concepts should be used wherever possible. This ensures simplicity and minimalize the possible errors.



Porkoláb Zoltán 2001-09-03