Component Software Beyond Object-Oriented Programming Clements Szyperski Chapter 7 – Object versus class composition or how to avoid inheritance Alexandre.

Slides:



Advertisements
Similar presentations
Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
Advertisements

Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Object Oriented System Development with VB .NET
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition.
On the horizon Chapter twenty-five of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSSE501 Object-Oriented Development
Inheritance using Java
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
1 Computer Science 340 Software Design & Testing Inheritance.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
1 COMP313A Programming Languages Object Oriented Progamming Languages (3)
OO as a language for acm l OO phrase l Mental model of key concepts.
Chapter FifteenModern Programming Languages1 A Second Look At Java.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Dynamic Binding Object-Oriented Programming Spring
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Object Oriented Programming
ISBN Object-Oriented Programming Chapter Chapter
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CSE119 Component Based Technology. UNIT – IV Java and CORBA Interface Definition Language Object Request Broker System Object Model Portable Object Adapter.
Object vs Class composition By Marine Ruhamanya. Disciplined Inheritance  Problems with implementation inheritance: Encapsulation Fragile Base Class.
Copyright 2010 by Pearson Education Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
Reuse Contracts A Historic Overview Dr. Tom Mens Programming Technology Lab Vrije Universiteit Brussel Course OOSE.RC EMOOSE
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Object Oriented Programming in Java Habib Rostami Lecture 2.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Sections Inheritance and Abstract Classes
Inheritance and Polymorphism
Lecture 12 Inheritance.
Component Based Software Engineering
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Section 11.1 Class Variables and Methods
Decorator Pattern Richard Gesick.
Objects and Aspects: What we’ve seen so far
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Presentation transcript:

Component Software Beyond Object-Oriented Programming Clements Szyperski Chapter 7 – Object versus class composition or how to avoid inheritance Alexandre Alvaro Universidade Federal de Pernambuco (UFPE)

Agenda Overview Various aspects of Inheritance Problems – Fragile base class problems Approaches to discipline inheritance From class to object composition – Forwarding x Delegation

Inheritance – the soup of the day ? Simula – Inheritance of implementation – Inheritance of interfaces – Establishment of substitutability Smalltalk – Inheritance of implementation – Inheritance of interfaces

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

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

More flavors to the soup Multiple Inheritance

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 ? Diamond inheritance problem

More flavors to the soup Mixing implementation fragments… Diamond inheritance problem About C class ?

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

More flavors to the soup Mixins E

More flavors to the soup Mixins Interface B { void X (); void Y (); } abstract class X1 implements B { void X () {... // X2.Y (); } abstract class X2 implements B { void Y () {... }

Back to basic ingredients… The fragile base class problem SO Application Base Class(es) Application

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

The fragile base class problem 1ª 2ª 3ª

The fragile base class problem 1ª 2ª 3ª

The fragile base class problem 1ª 2ª 3ª

The fragile base class problem 1ª 2ª 3ª

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 ContractsVersions Re-entrance

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(); }....

Inheritance – more knots than meet the eye 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(); }.... X

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

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

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}... } No dependencies

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

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

Approaches to discipline inheritance 3) Behavioral specification of the specialization interface A B C Class Three groups

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}... } Only among methods

Approaches to discipline inheritance 4) Reuse and cooperation contracts – Real innovation Set of modification operators – Concretization – Extension – Refinement

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.

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

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

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 Fragile subclass problem

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

From class to object composition Object A Object B > Forwarding Delegation ? inner object outer object Difference between Inheritance and Forwarding ?

Forwarding x Delegation Forwarding – Regular Message Delegation – Self-recursive one – Strengthened – Identity is remenbered What the diference between Forwarding and Delegation ?

Forwarding x Delegation InsertChar SetCaret InsertChar delegate(InsertChar) delegate(SetChar) resend(SetChar) ForwardingDelegation