Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4289

Re: Composition instead of inheritance

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Composition instead of inheritance
References <mailman.967.1304030151.9059.python-list@python.org> <4dba22f3$0$29978$c3e8da3$5496439d@news.astraweb.com>
Date 2011-04-29 13:50 +1000
Message-ID <87k4edk95u.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> On Thu, 28 Apr 2011 15:35:47 -0700, Carl Banks wrote:
>
> > That's not what we mean by composition. Composition is when one
> > object calls upon another object that it owns to implement some of
> > its behavior.
>
> I thought that was delegation. As in, when one object delegates some or 
> all of it's behaviour to another object:
>
> http://code.activestate.com/recipes/52295

The difference being that, with delegation, the object being called is
unrelated to this one. With composition, the object being called is not
wholly separate, but is instead an attribute on the current object.

The “another object that it owns” was, I presume, meant to communicate
this “an object which is an attribute of the current one” relationship.

> In mathematics, composition means to make a function by applying a 
> function to the output of another.

The term “composition” in the programming sense comes from OO design,
not functional nor mathematical terminology.

-- 
 \          “I don't like country music, but I don't mean to denigrate |
  `\          those who do. And for the people who like country music, |
_o__)                        denigrate means ‘put down’.” —Bob Newhart |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Composition instead of inheritance Carl Banks <pavlovevidence@gmail.com> - 2011-04-28 15:35 -0700
  Re: Composition instead of inheritance Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-29 02:31 +0000
    Re: Composition instead of inheritance Ben Finney <ben+python@benfinney.id.au> - 2011-04-29 13:50 +1000
    Re: Composition instead of inheritance Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-04-28 20:57 -0700

csiph-web