November 2, 2010

Inheritance models.

Hi, Here I keen to describe only practical models.


There is general properties of model which measures amount of information we can capture using this model.

Let say we describe some particular system using set of properties. Arrangements of properties constrained by inheritance model that we choose.

Models differ by redundancy it require (encapsulation vs. delegation) and reuse it provides (inheritance vs. inclusion).

Numerically we can capture redundancy by combinatory complexity but reuse can only feet in functor which doesn't have something like adjustency degree (? or does it).


Lets us look for model in the field of `modern` programming  languages.

Java diagonal inheritance model



There is two parallel hierarchies: one for interfaces and one for Implementation. Final class ready to produce system object (object which describe system we model) when it derived from proper implementation of interfaces exposed by our system.


Interfaces diagonal is redundant, it just a shadow of Implementation, has no properties and do nothing.
Implementation can be reused along Impl diagonal. Suppose we have 3 class diagonal and each class add one unique property. Model that can be build from it is power set of properties:

P {a, b, c} = {{}, {a}, {b}, {c}, {a,b}, {b,c}, {a,c}, {a,b,c}}

If no overwriting on parameters assumed, the only interesting model is complete diagonal - {a,b,c}.





C++ diamond inheritance model.


C++ employs virtual derivation schema when subtypes keeps parental properties or override them. This model can scale in any direction and is famous for its tendency for over-design.

Diamond models are domain specific and used mostly by frameworks.  No reuse achieved ever.

Previous (Diagonal) model scaling linearly from number of properties. But on diamond we can do permutations, so number of domain model described is factorial. 




Mixins model (includes: good C++, most of C#, Scala, all but bad JavaScript).

It's theoretical thus very orthogonal.

Prototype class
^
Component class (+) trait* 


Mixins is about sharing behavior between objects. There are anchors embedded into `Prototype class on which all traits agreed and synchronize. Anchor can be any kind ranging from enumeration to type constructors.   

This model is very powerful and can "bless" any class with additional behavior.

Comparative to previous discussed models  this one is real Functor. It works on constant property set (anchors). It creates new domain model by mixing traits.


No comments:

Post a Comment