Re: Disadvantages of Inheritance, Polymorphism and Encapsulation

From: Phlip (phlip_cpp_at_yahoo.com)
Date: 01/25/05


Date: Tue, 25 Jan 2005 15:40:27 GMT

X-posted to news:comp.object

Robert Gale wrote:

> I have an exam tomorrow that covers the perceived advantages and
> disadvantages of object oriented programming, in particular
> polymorphism, inheritance and encapsulation. I know the advantages but
> am not clear on the disadvantages. I have had a look on the Web and in
> newsgroups but couldn't find much. As time is running out, I thought I
> would post here and hope that someone would reply.

The goal is code that's flexible and easy to change.

Two objects should associate by the weakest possible link. If object Foo
calls object Bar's method Frob(), all Foo should know of Bar is that it has
such a method. Bar, in return, should not surprise Foo. This is
"decoupling", and it implies when you change Foo you need only attend to the
tiny part of Bar that Foo uses. Changes to Foo should not ripple all the way
into Frob(), and vice versa.

When two classes associate by inheritance, they couple more strongly.
Changes to Foo have higher risks to Bar. If Bar inherits Foo and overrides
Frob(), Bar (in theory) must not do anything that could break any of Foo's
clients, because they might someday start calling Bar::Frob().

The strongest association is friendship, which implies no capsule boundary
between Foo or Bar. Changes to each have a very high risk of breaking the
other. However, if friendship allows both Foo and Bar to present a smaller
interface to other clients, then they have a stronger encapsulation, and
lower risk of changes rippling.

Now e-search...

 - Liskov Substitution Principle
 - Law of Demeter
 - Open Closed Principle
 - Dependency Inversion Principle

-- 
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces


Relevant Pages

  • Re: Class inheritance
    ... > class Foo ... > class Bar ... > function FooBar() ... > than inheritance, but it seems to me the effect is close. ...
    (comp.lang.php)
  • Re: Insert with response
    ... FooBar, there's no way and no need to put them in synch. ... column in the foo table to 250 calumns in the bar table. ... set statistics time off ...
    (microsoft.public.sqlserver.programming)
  • Re: Magic function
    ... processing objects created in root at depth 3 ... root obj2 at depth 3 ... processing objects created in foo at depth 2 ... processing objects created in bar at depth 0 ...
    (comp.lang.python)
  • Re: Operators Inherited?
    ... got two types, Foo and Bar, with values foo and bar: ... it'll look in the namespaces of both Foo and Bar for static methods ... includes polymorphism by way of inheritance, ...
    (microsoft.public.dotnet.general)
  • Re: from __future__ import absolute_import ?
    ... foo not in bar ... Unfortunately this is a side effect of using the os's directory structure to represent a python "package" structure. ...
    (comp.lang.python)