In OOP, "layering" is the technique of building one class on top of another. For instance (C++) -

class Animal {
  string name; // layered object
  Head myHead; // another layered object
  Body myBody; // guess what
};

As above, layering is used to implement "hasa" relationships. You don't use public inheritance in this case, because that's used for "isa" relationships. If you said an Animal "isa" Head, you'd be a fool, which is why you use layering to show it "hasa" Head.

Layering can also be used for "is-implemented-in-terms-of" relationships. For instance, a deque in the C++ STL might be implemented by a vector, in which case it would contain a layered vector object which is manipulated by the deque class.

In general, layered objects, like any data member in a class, should have private access control. This is especially true for "is-implemented-in-terms-of" relationships - imagine what would happen to our deque if people could fiddle around with its private parts. It wouldn't be pretty.

This is, of course, in compliance with the Law of Demeter. No module has any business messing around with another module's component parts, and all transactions between modules should take place with member functions. No good rarely comes of letting one module access another's layered objects - after all, their behaviour should be encapsulated by the parent class, other modules don't even need to know they exist.

More

Lay"er*ing, n.

A propagating by layers.

Gardner.

 

© Webster 1913.

Log in or register to write something here or to contact authors.