Re: Disadvantages of Inheritance, Polymorphism and Encapsulation
From: Phlip (phlip_cpp_at_yahoo.com)
Date: 01/25/05
- Next message: Mark Nicholls: "Re: Liskov Substitution Principle and Abstract Factories"
- Previous message: Robert Klemme: "Re: Objects in a multiprocessor architecture"
- Next in thread: topmind: "Re: Disadvantages of Inheritance, Polymorphism and Encapsulation"
- Reply: topmind: "Re: Disadvantages of Inheritance, Polymorphism and Encapsulation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Mark Nicholls: "Re: Liskov Substitution Principle and Abstract Factories"
- Previous message: Robert Klemme: "Re: Objects in a multiprocessor architecture"
- Next in thread: topmind: "Re: Disadvantages of Inheritance, Polymorphism and Encapsulation"
- Reply: topmind: "Re: Disadvantages of Inheritance, Polymorphism and Encapsulation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|