Component%20Software%20Beyond%20Object-Oriented%20Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Component%20Software%20Beyond%20Object-Oriented%20Programming

Description:

Chapter 7 Object versus class composition or how to avoid ... { caret = pos; class SimpleText extends Text{ void setCaret (int pos) { int old = caretPos ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 38
Provided by: alexandr94
Category:

less

Transcript and Presenter's Notes

Title: Component%20Software%20Beyond%20Object-Oriented%20Programming


1
Component Software Beyond Object-Oriented
Programming
  • Clements Szyperski
  • Chapter 7 Object versus class composition or
    how to avoid inheritance

Alexandre Alvaro aa2_at_cin.ufpe.br Universidade
Federal de Pernambuco (UFPE)
2
Agenda
  • Overview
  • Various aspects of Inheritance
  • Problems
  • Fragile base class problems
  • Approaches to discipline inheritance
  • From class to object composition
  • Forwarding x Delegation

3
Inheritance the soup of the day ?
  • Simula 67 - 1970
  • Inheritance of implementation
  • Inheritance of interfaces
  • Establishment of substitutability
  • Smalltalk - 1983
  • Inheritance of implementation
  • Inheritance of interfaces

4
Inheritance the soup of the day ?
  • Eiffel
  • Possible to undefine inheritance interface
    feature
  • Emerald (1987), Java, C
  • Interface and implementation inheritance have
    been separated
  • COM and OMG IDL
  • Interface definition language

5
Inheritance the soup of the day ?
  • Three facets of inheritance
  • Subclassing
  • Subtyping
  • Promise of substitutability
  • How to avoid inheritance ?

6
More flavors to the soup
  • Multiple Inheritance

7
More flavors to the soup
  • Mixing implementation fragments

Do both superclasses B1 and B2 get their own copy
of the state defined by the superclass A ?
8
More flavors to the soup
  • Mixing implementation fragments

About C class ?
Diamond inheritance problem
9
More flavors to the soup
  • Some approaches to discipline
  • CLOS (Common Lisp Object System)
  • Linear order of inheritance
  • C
  • Maintaining the integrity of sub-objects
  • Java
  • Limited to single implementation inheritance
  • OMG IDL and COM
  • Not support implementation inheritance at all

10
More flavors to the soup
  • Mixins

11
More flavors to the soup
  • Mixins

abstract class X1 implements B void X ()
... // X2.Y ()
Interface B void X () void Y ()
abstract class X2 implements B void Y ()
...
12
Back to basic ingredients
  • The fragile base class problem

Application
Application
Application
Base Class(es)
SO
13
The fragile base class problem
  • Syntatic
  • Binary compatibility
  • Compiled classes with new binary releases of
    superclass
  • Not need recompilation after syntatic changes
  • Example methods may move up in the class
    hierarchy

14
The fragile base class problem
1ĀŖ 2ĀŖ 3ĀŖ
15
The fragile base class problem
1ĀŖ 2ĀŖ 3ĀŖ
16
The fragile base class problem
1ĀŖ 2ĀŖ 3ĀŖ
17
The fragile base class problem
1ĀŖ 2ĀŖ 3ĀŖ
18
The fragile base class problem
  • Semantic
  • How can a subclass remain valid in the presence
    of different version of its superclasses ?
  • Parameters
  • Methods name
  • Return type

Contracts
Versions
Re-entrance
19
Inheritance more knots than meet the eye
abstract class Text ... void write (pos, ch)
.... setCaret (pos) void setCaret
(int pos) caret pos ...
class SimpleText extends Text ... void setCaret
(int pos) int old caretPos() if (old
! pos) hideCaret()
super.setCaret(pos) showCaret()
....
20
Inheritance more knots than meet the eye
X
abstract class Text ... void write (pos, ch)
.... pos void setCaret (int
pos) caret pos ...
class SimpleText extends Text ... void setCaret
(int pos) int old caretPos() if (old
! pos) hideCaret()
super.setCaret(pos) showCaret()
....
21
Approaches to discipline inheritance
  • 1) The specialization interface
  • C, Java, C
  • Protected
  • Acessible only to subclasses
  • Public
  • The client interface
  • Private
  • Private to a class, not an object

22
Approaches to discipline inheritance
  • 2) Typing the specialization interface
  • What are the legal modifications a subclass can
    apply ?
  • Protected interface
  • 1993, John Lamping
  • Statically
  • Acyclic
  • Arranged in layers
  • Cyclic
  • Form a group

23
Approaches to discipline inheritance
  • 2) Typing the specialization interface
  • The developer determines the groups or layers

specialization interface Text state
caretRep state textRep abstract
posToXCoord abstract posToYCorrd concrete
caretPos caretPos concrete setCaret
caretRep concrete write textRep, caretPos,
setCaret concrete delete textRep, caretPos,
setCaret ...
24
Approaches to discipline inheritance
  • 3) Behavioral specification of the specialization
    interface
  • Semantic issues
  • 1995, Stata Guttag
  • Class as a combined definition of interacting
    parts objects
  • Method groups
  • Algebraic specification techniques
  • Notion of behavioral subtyping

25
Approaches to discipline inheritance
  • 3) Behavioral specification of the specialization
    interface

Inheritance Independent classes
26
Approaches to discipline inheritance
  • 3) Behavioral specification of the specialization
    interface

A
B
C
Class Three groups
27
Approaches to discipline inheritance
  • 4) Reuse and cooperation contracts
  • 1996, Steyaert, et. al.
  • Returned to the idea of statically verifiable
    annotations
  • Reuse contract

reuse contract Text abstract
posToXCoord posToYCorrd concrete
caretPos setCaret write caretPos,
setCaret delete caretPos, setCaret ...
28
Approaches to discipline inheritance
  • 4) Reuse and cooperation contracts
  • Real innovation
  • Set of modification operators
  • Concretization
  • Extension
  • Refinement

29
Approaches to discipline inheritance
  • 5) Representation invariants and methods
    refinements
  • 1996, Edwards
  • Generalization of the Stata Guttag
  • Overriding a method in a method group
  • Associating invariants with a class
  • Protected
  • Public
  • Private
  • Etc.

30
Approaches to discipline inheritance
  • 6) Disciplined inheritance to avoid fragile base
    class problems
  • 1998, Mikhajlov Sekerinski

31
Approaches to discipline inheritance
  • 7) Creating correct subclasses without seeing
    superclass code
  • 2000, Ruby Leavens
  • Inverse problem of the semantic FBC problem

Inverse problem FBC problem
32
Approaches to discipline inheritance
  • 7) Creating correct subclasses without seeing
    superclass code
  • 2000, Ruby Leavens
  • Inverse problem of the semantic FBC problem

Fragile subclass problem
Inverse problem FBC problem
33
Approaches to discipline inheritance
  • 7) Creating correct subclasses without seeing
    superclass code
  • Provide 3 parts to a class specification
  • Public
  • Protected
  • Automatic analysis of the initial source code of
    the base class

34
From class to object composition
outer object
inner object
ltltmessagegtgt
Object B
Object A
Delegation ?
Difference between Inheritance and Forwarding ?
35
Forwarding x Delegation
  • Forwarding
  • Regular Message
  • Delegation
  • Self-recursive one
  • Strengthened
  • Identity is remenbered
  • What the diference between Forwarding and
    Delegation ?

36
Forwarding x Delegation
Forwarding Delegation
InsertChar InsertChar SetCaret
InsertChar delegate(InsertChar) delegate(SetChar)
resend(SetChar)
37
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com