OO as a language for acm l OO phrase l Mental model of key concepts.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Advertisements

Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
C12, Polymorphism “many forms” (greek: poly = many, morphos = form)
Chapter 7 Testing Class Hierarchies. SWE 415 Chapter 7 2 Reading Assignment  John McGregor and David A. Sykes, A Practical Guide to Testing Object-Oriented.
Inheritance Inheritance Reserved word protected Reserved word super
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Chapter 10 Class and Method Design
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Chapter 10 Classes Continued
Abstract Data Types and Encapsulation Concepts
Slide 1 Chapter 10 Class and Method Design. Slide 2 REVISITING THE BASIC CHARACTERISTICS OF OBJECT-ORIENTATION.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSC 142 O 1 CSC 142 Java More About Inheritance & Interfaces [Reading: chapter 13]
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
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.
Class Design III: Advanced Inheritance Additional References “Object-Oriented Software Development Using Java”, Xiaoping Jia, Addison Wesley, 2002 “Core.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Session 24 Chapter 12: Polymorphism. Polymorphism polymorphism comes from the Greek root for “many forms” polymorphism is about how we can use different.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
ISBN Object-Oriented Programming Chapter Chapter
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Coming up: Inheritance
Session 18 Lab 9 Re-cap, Chapter 12: Polymorphism & Using Sound in Java Applications.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
CSCI-383 Object-Oriented Programming & Design Lecture 24.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism in Methods
Inheritance and Polymorphism
11.1 The Concept of Abstraction
Subtype Polymorphism, Subtyping vs
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
11.1 The Concept of Abstraction
Presentation transcript:

OO as a language for acm l OO phrase l Mental model of key concepts

History l Birth of OO dates to Simula 67 l 35 years ago l Simula introduced all the fundamental OO concepts

History l Simula (and OO) are rooted in abstract data types, separation of concerns, classification schemes dating from Aristotle, discrete event simulation l Formal foundations in behavioral subtyping (LSP), object calculi l Aspect-oriented programming (modularity in more than one dimension)

Modules Class  Ada83 package spec that defines a record type & associated operations Object  instance of record type A

Data Attribute  Record field public (+) private (-) protected (#) A

Code Operation  subprogram spec Also public (+), protected (#), private (-) Method  subprogram body Signature, e.g. “ m (p: Integer) ” Overloading Constructor Destructor A

‘ Generics ’ Template class  generic package A parameters

Phrase book, page 1 l Class l Attribute l Public l Private l Protected l Operation l Method l Signature

Phrase book, page 2 l Overloading l Constructor l Destructor l Class instance = object l Template class

Calls x: A; … x.m(i); Declared type Remaining arguments Target object A m(a: int)

Interfaces … concrete classes Interface client operations only Abstract class some attributes some operations, some methods Concrete class attributes methods A > B C

Phrase book, page 3 l Declared type l Target object l Interface l Abstract class l Concrete class

“ Contracts ” Precondition Postcondition Invariant A

Interface inheritance Generalization Superinterface A Subinterface B A B

B inherits the operations of A It may also override them  And may add operations of its own m (a: int) n (x: int) : float o () n (a: int): float Interface inheritance A B

Inheritance “ math ”

Liskov Substitution Principle n (x: int) : float l Precondition of , must require the same or less than the precondition of  l Postcondition of , must deliver the same or more than the postcondition of  We can test for this by “ inheriting ” all test cases

All B ’ s are A ’ s Anywhere we use an A, we use a B Substitutability A B

Interface inheritance A superinterface may also have more than one subinterface B A C

Phrase book, page 4 l Interface inheritance l Superinterface l Subinterface l Overriding

Phrase book, page 5 l Generalization l Liskov Substitution Principle (LSP) l Precondition l Postcondition l Invariant

Interface implementation Realization Class B “ realizes ” interface A In accordance with LSP A B

Multiple implementations More than one class may “ realize ” a given interface Partial implementation by abstract subclass Full implementation by concrete subclass A BC D

Implementation inheritance Superclass Subclass Still in accordance with LSP C D

Implementation inheritance A superclass may have more than one subclass D C E

Polymorphism x: A = new B; … x.m(i); Variable may reference any object of its declared type or any of its subtypes (polymorphism) Run time type of an object is set when it is created, and never changes Run-time type Declared type A BC D m(a: int)

Polymorphism for each display element element.draw() end DisplayElement importance : int xOrigin : CoordinateValue yOrigin : CoordinateValue draw() highlight() hide() NonTextualElement highlight() PrimitiveNonTextualElement draw() highlight() AltitudeTape width : GraphicsDistance height : GraphicsDistance colorScheme : ColorScheme displayedValue : Altitude draw() getDisplayedValue() : Altitude setDisplayedValue(altitude : Altitude) AirspeedTape draw() getDisplayedValue() : Airspeed setDisplayedValue(airspeed : Airspeed) Compass radius : GraphicsDistance colorScheme : ColorScheme displayedValue : Heading draw() getDisplayedValue() : Heading setDisplayedValue(heading : Heading) TextualElement width : GraphicsDistance height : GraphicsDistance displayedValue : String draw() highlight() getDisplayedValue() : String setDisplayedValue(string : String) width : GraphicsDistance height : GraphicsDistance colorScheme : ColorScheme displayedValue : Altitude

Dynamic dispatch Polymorphism + multiple methods  dispatch l All display elements have a draw operation l We need to call the right implementation of draw l Right = the one that matches the run time type associated with the object when it was created

Dynamic Dispatch Call to draw is semantically equivalent to a case statement for each display element case of display element ’ s run time type case (AltitudeTape) call AltitudeTape.draw() case (AirspeedTape) call AirspeedTape.draw() case (Compass) call Compass.draw() case (PrimitiveNonTextualElement) call PrimitiveNonTextualElement.draw() case (TextualElement) call TextualElement.draw() end

l In general, method selection is a function of the run time type and the method signature l Conceptually there is a single dispatch routine for all calls containing a pair of nested case statements case of target object ’ s run time type - (1) case ( ) case of method signature - (2) case ( ) call defined by -- (3) end In practice, calls to this universal dispatch method are ‘ inlined ’ at the point of call Dynamic Dispatch

Typically implemented using “ dispatch tables ” l Small, fixed overhead l At the point of call: (1) get the dispatch table associated with the target object, (2) index it by a number associated with the method signature, and (3) invoke the method Dynamic Dispatch … dispatch table for type targetObject run time type

Phrase book, page 6 l Realization l Polymorphism l Declared type l Run-time type l Dynamic dispatch l Dispatch table

Multiple interface inheritance  More than one superinterface  Inherited elements represent only specs  No code or data BA C

Multiple implementation inheritance  More than one superclass  Inherited elements represent code and data in addition to specs  Inherited elements may reference one another BA C

Phrase book, page 7 l Multiple interface inheritance l Multiple implementation inheritance

Whole-part associations Aggregation XY Composition Whole Part XY

Delegation A B Delegate m(a: int) Delegation, e.g., of all calls to B::m(int) to A::m(int) “Do it yourself” inheritance

Inheritance + delegation  Single inheritance + delegation  “Inheritance of implementation from” one superclass  “Delegation to” the implementation of the other BA C

Phrase book, page 8 l Association l Aggregation l Composition l Delegation

Other related concepts l Use cases l Patterns l Aspects, join points, aspect weaving

Primary advantages of OO l Improved coupling/cohesion l Isolation of likely future changes l Product families l Reuse - of specifications, code, test cases l Explicit specification of when one component is substitutable for another l Explicit criteria for testing this (LSP)