Type and subclassing

Posted on December 5, 2008

I was reading Snyder’s 86 paper where he describes how inheritance violates encapsulations and it helped me realized the reason for duck typing.

In most modern OO languages we define a subtype (of class A) by inheritance (B : implements A). However what if B can be implemented more efficiently by using different algorithms while at the same time preserving the same programming interface (type). But now A and B have no common ancestors and in most languages will be treated as different types. So you can’t pass B to code that expects an object of type or subtype of A. To avoid this problem Snyder recommends to separate sub-typing from inheritance. Instead sub-typing should be based in behaviour of the objects. If instances of class B meet the external interface of class A, then B  should be a subtype of A.

ps I thing functional languages like haskell and skala treat type issue more seriously.

Filed Under Uncategorized | Leave a Comment

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name

Email

Website

Comments

© Copyright 0xDEADBEEFCAFE • Powered by Wordpress • Design by Sebastin.

free web hit counter