Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with...
-
Upload
anna-bishop -
Category
Documents
-
view
224 -
download
1
Transcript of Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with...
![Page 1: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/1.jpg)
Object vs Class composition
By Marine Ruhamanya
![Page 2: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/2.jpg)
Disciplined Inheritance
Problems with implementation inheritance: Encapsulation Fragile Base Class problem
However it is a powerful mechanism.
Several attempts to discipline the mechanism
![Page 3: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/3.jpg)
The specialization interface
Special interface between a class and its subclasses
C++, Java, C# support the notion of protected features of a class
![Page 4: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/4.jpg)
Typing the specialization interface
Overriding methods needs to be done carefully
Proposal (Lamping,1993): Type system to improve control
Declare method dependencies Acyclic graph => methods arranged in layers Cycles => all methods form a group
Subclass has to override methods group by group
![Page 5: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/5.jpg)
Behavioral specification
Semantic issues of implementation inheritance: mostly related with re-entrance caused
by self-recursion Proposal (Stata and Guttag, 1995):
View a class as a combined definitions of interacting parts objects
Division of labor or method groups No direct access between divisions
![Page 6: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/6.jpg)
Behavioral specification(2)
Use of specification techniques and the notion of behavioral subtyping
Stata-Guttag vs Lampig: Stata-Guttag: split state and behavior
into groups. Methods groups encapsulate part of the state
Lampig: any dependency of methods on state
Tight semantic control leads to object composition.
![Page 7: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/7.jpg)
Reuse contracts
Less restrictive forms of implementation Proposal (Stayeart et al., 1996):
Annotated interface: reuse contracts Determine how reuse happens between
classes and its subclasses Specify structural aspects of a base class Specify only the part of a call stucture
subclasses can rely on. New: set of modification operators
![Page 8: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/8.jpg)
Representation Invariants & Methods Refinements
Proposal (Stephen, 1999): Associate invariants to a class
specification that refers to protected variables
Proposal (Stata, 1999): Separate the notion of subtyping and
subclassing to allow partial overriding Supercalls are allowed if overriding
method is a proper refinement of the base class method.
![Page 9: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/9.jpg)
Disciplined inheritance to avoid the FBC problem
Proposal (Mikhajlov-Sekerinski, 1998): Set of rules: Construction of subclasses based on superclass
specification Eliminate the introduction of new cyclic
method dependencies Superclasses instance variables are private
and subclasses don’t introduce new ones. Very restrictive, but interesting formal
proof
![Page 10: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/10.jpg)
Creating subclasses without seeing the superclass code
Proposal (Leavens et al., 2000): Java Modeling Language defined Focus on the inverse of FBC problem Provide 3 parts to a class specification:
1st and 2nd : public and protected parts 3rd: subclassing contract provide information
accessed variables and methods call dependencies
Link to the FBC not further explored.
![Page 11: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/11.jpg)
From Class to Object Composition
Object composition - simpler form of composition:
Object send message to other object asking for support; Outer and inner objects, forwading
Differences to implementation inheritance; Outer object does not reimplement inner
object functionality ‘Implicit self-recursion’ or ‘possesion of
common self’
![Page 12: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/12.jpg)
From Class to Object Composition
‘Implicit self-recursion’ or ‘possession of common self’: There is no ‘common self’ in object
composition In implementation inheritance: upcalls
due to method invocation Example ( page 135).
Advantage: dynamic
![Page 13: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/13.jpg)
Forwarding vs Delegation
Message passing Delegation: message-send is classified as
either regular (forwarding) or self-recursive (delegation)
Example (page 136 &137) Message resending Complexity exploses under delegation Interaction diagram similar to that of
implementation inheritance
![Page 14: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/14.jpg)
Delegation & Inheritance Delegation – powerful programming tool System based on OC and delegation are
highly dynamic. Languages are called prototype-based
languages; e.g.: Self. Not yet mainstream
Delegation is behind in discipline and modularity while inheritance is behind in system dynamics and late compsition
![Page 15: Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance Problems with implementation inheritance: Encapsulation Fragile Base Class.](https://reader036.fdocuments.net/reader036/viewer/2022082713/5697c0281a28abf838cd6e27/html5/thumbnails/15.jpg)
End