[BNE-PM] OO perl
Tony Obermeit
tonyob at compuserve.com
Tue Aug 20 16:21:00 CDT 2002
>Tony, can you give a breif summary of object composition and aspect
>oriented programming? Is this a move away from one of the fundamentals of
>OO -namely inheritance?
Object composition
One problem with inheritance is that it breaks encapsulation because a
subclass depends on how it's superclass is implemented. Instead of
extending an existing class, give your new class a private field that
references an instance of the existing class, this is what is referred to
in composition. Do a search on google of +favor +composition +over
+inheritance to get links to articles and books that provide more detailed
examples of this.
This shouldn't be taken as a view to ban the use of inheritance, but rather
to treat it more carefully than we might have otherwise.
Aspect Oriented Programming (AOP)
This isn't seen by it's promoters as a move away from the fundamentals of
OO, but rather an enhancement to or continuing evolution of OO. Aspect
oriented programming helps to implement contract by design which is tied to
the pre and post conditional tests mentioned previously in this
thread. AspectJ implements AOP by providing a precompiler. This
precompiler generates the constructs necessary to implement aspects in java.
One example of an aspect is the creation of a compile time warning if code
sets a non-public fields outside of the scope of a setter method. Another
example is enforcing a rule that states that all our factory methods must
not return a null object.
It's outside the scope of my response to properly describe AOP, I recommend
the following article for an overview or go to www.aspectj.org for other
links. You will need to register to get the following article but that
experience wasn't too painful for me.
http://www.sdmagazine.com/documents/s=7134/sdm0205b/0205b.htm
cheers
Tony
More information about the Brisbane-pm
mailing list