Engr 691-10: Special Topics in Engineering Science
Software Architecture
Spring Semester 2002
Lecture Notes


Replacement and Refinement

This Web document was based on a set of "slides" created by the instructor for use in the Fall 1997 and Spring 1999 offerings of the object-oriented design and programming course. That set was, in turn, based on a set of slides created by Timothy Budd to supplement chapter 11 of his textbook An Introduction to Object-Oriented Programming, Second Edition (Addison-Wesley, 1997).


Replacement and Refinement

What happens when child classes have methods with the same names as parent?

There are two general models describing this situation:

Replacement:
"American" school of OOP -- child method replaces parent method

Refinement:
"Scandinavian" school of OOP -- behavior of parent and child classes are merged to form new behavior

If replacement used, then some mechanism usually provided for refinement

If refinement default, then replacement not possible


Preserving is-a

Replacement makes preserving principle of substitutability difficult


Documenting Replacement or Refinement


Replacement in Java


Refinement


Refinement in Simula and Beta


Refinement in Java

public class CardPile 
{   public CardPile (int xl, int yl) 
    { x = xl; y = yl; thePile = new Stack(); }

    public void addCard (Card aCard) { thePile.push(aCard); }
    ...
}

class DiscardPile extends CardPile 
{   public DiscardPile (int x, int y) { super (x, y); }

    public void addCard (Card aCard) 
    {   if (! aCard.faceUp())
            aCard.flip();
        super.addCard(aCard);
    }
    ...
}


UP to ENGR 691 Lecture Notes root document?


Copyright © 2002, H. Conrad Cunningham
Last modified: Sun 12 Oct 2003