ObjectOriented Composition Untangled - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ObjectOriented Composition Untangled

Description:

Object-Oriented Composition Untangled. Mira Mezini. Software Technology Group ... formerly Sparkasse Bonn, now Sparkasse Munich. had to update numerous bank details ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 24
Provided by: OSTER
Category:

less

Transcript and Presenter's Notes

Title: ObjectOriented Composition Untangled


1
Object-Oriented Composition Untangled
2
A Little Story About Recent Moves ...
It was really frustrating...
It was really frustrating...
  • My bank account changed
  • formerly Sparkasse Bonn, now Sparkasse Munich
  • had to update numerous bank details
  • My email address changed
  • formerly ostermann_at_cs.uni-bonn.de, now
    Klaus.Ostermann_at_mchp.siemens.de
  • had to inform many friends and colleagues
  • My ACM email address did not change!
  • still kos_at_acm.org
  • Mail is automatically forwarded to my actual
    address

3
Transparent Redirection is Ubiquitous
  • e-mail
  • phone
  • symbolic links in Unix file systems
  • URL redirection
  • many mechanisms in distributed systems
  • However
  • no explicit notion of transparent redirection in
    OOPL

4
Account Example
  • Modifying a persons account invalidates standing
    orders
  • No satisfactory OO solution available (see paper)

5
Core of the ProposalRedirection with Compound
References
Account
jack.account ubsAccount anAccount
jack.account jacksAccount jacklt-account //
xxx jack.account dbAccount
Account
Person
6
Core of the Proposal Redirection with Compound
References
Account
jack.account ubsAccount anAccount
jack.account jacksAccount jacklt-account //
xxx jack.account dbAccount
Account
Person
7
Account Example Reconsidered
class Person Account account Account
getAccount() return account Account
getPersonsAccount() return thislt-account
void setAccount(Account newAccount)
account newAccount
8
Observation Inheritance/Delegation Imply
Redirection
  • Inheritance
  • Method calls automatically redirected to
    superclass
  • Delegation
  • Even closer to CR Parent objects can be
    exchanged, similar to accounts with CRs
  • However, delegation is more than plain CRs
  • CRs seem to be in the middle of the path
    between object composition and inheritance/delegat
    ion

9
Composition Properties
Modules M and B, Composition M(B)
  • Overriding In M(B) definitions in M override
    definitions in B with the same name
  • Transparent Redirection Within B this refers to
    M(B)
  • Acquisition Bs features can be used in M(B) as
    if they were M(B)s features.
  • Subtyping M(B) can be used wherever B is
    expected.
  • Polymorphism The ability to (dynamically or
    statically) apply M to subtypes of B.

10
Mapping of Composition Properties
11
The TextJustifier Example
TextJustifier Example
12
TextJustifier Example
compose
13
TextJustifier ExampleComposition by Inheritance
  • TextJustifier is subtype of TreeIterator (no
    subtyping)
  • Methods of TreeIterator pollute the TextJustifier
    interface (no acquisition)
  • Design gets complex if different traversal
    strategies, should be selected at runtime
    (polymorphism)

14
TextJustifier ExampleDesign for Dynamic
Composition
  • Different from previous design
  • Complex !
  • See paper for more details

15
Field Methods and Overriding
  • class TextJustifier
  • private Iterator it
  • public void justify() ... it.doAll() ...
  • // begin of implicitly available field
    methods
  • private void it.doAll() field.doAll()
  • ...
  • private void it.action(Item x)
    field.action(x)
  • private boolean it.test(Item x)
  • return field.test(x)
  • // end of implicitly available field methods

Alias for it field
16
Field Methods and Overriding
class TextJustifier private redirect
TreeIterator it private void it.action() ...
private boolean it.test(Item x) ...
public void justify() ... it.doAll(...)
class TreeIterator public void doAll() ...
this.action() ... ...
17
The Stream Example
Stream Example
18
The Stream Example
  • BufferedOS requires redirection
  • LoggingOS does not work with redirection

19
Acquisition and Subtyping
BOS acquires all methods of OutputStream by
removing the field method prefixes
  • class OutputStream
  • ...
  • class BufferedOutputStream subtypeof OutputStream
  • acquire redirect OutputStream stream
  • ...
  • class LoggingOutputStream subtypeof OutputStream
  • acquire OutputStream stream
  • ...

BOS is subtype of OutputStream
20
Type Safety
  • Threatened by subtle combinations of CRs,
    subtyping, and dynamic binding.
  • Solution If critical CRs are created, the
    assignment historyis stored. Calls are
    dispatched to history objects if necessary.
  • Invariant CR refers to the current value of the
    corresponding variable is violated.

... a.b new B1() ... alt-b.foo() ... a.b new
B2()
21
Problem Summary
  • Frequently needed Composition semantics not
    provided by any of the standard mechanisms.
  • Consequence Simulation by architectures that
  • are complex,
  • are fragile with respect to requirement changes,
  • are difficult to change without invalidating
    existing clients,
  • restrain readability and maintainability of the
    code.

22
Independent Applicability of Properties
23
Conclusions
  • Composition mechanisms are untangled by
    rendering each property independently
    applicable.
  • Complicated simulation architectures no longer
    nedded.
  • Instead of expensive refactorings it suffices to
    add/delete property modifiers.
  • Overriding and redirection of multiple fields
    without multiple inheritance conflicts.
  • Model complicated by mechanisms to retain static
    type safety
Write a Comment
User Comments (0)
About PowerShow.com