Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.

Slides:



Advertisements
Similar presentations
Containers CMPS Reusable containers Simple data structures in almost all nontrivial programs Examples: vectors, linked lists, stacks, queues, binary.
Advertisements

Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSSE501 Object-Oriented Development
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Advanced Inheritance Concepts. In this chapter, we will cover: Creating and using abstract classes Using dynamic method binding Creating arrays of subclass.
Abstraction, Inheritance, and Polymorphism in Java.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Programming Languages and Paradigms Object-Oriented Programming.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Session 21 Chapter 10: Mechanisms for Software Reuse.
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.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Object Oriented Software Development
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Mechanisms for Reuse CMPS OOP billed as technology that permits software to be constructed from general-purpose reusable components Two main mechanisms.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Object-Oriented Programming Chapter Chapter
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
ISBN Object-Oriented Programming Chapter Chapter
Coming up: Inheritance
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.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
C10, Mechanisms for Software Reuse. Substitutability A variable declared as one type holds a value of another type In Java either: Subclass: allPiles.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
ISBN Chapter 12 Support for Object-Oriented Programming.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Modern Programming Tools And Techniques-I
Sections Inheritance and Abstract Classes
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Chapter 10 Thinking in Objects
Chapter 9 Carrano Chapter 10 Small Java
Advanced Inheritance Concepts
Chapter 10: Mechanisms for Software Reuse
Presentation transcript:

Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes

Mechanisms for Software Reuse (Budd's UOOPJ, Ch. 10) This is a set of slides originally created to accompany chapter 10 of Timothy Budd's textbook Understanding Object-Oriented Programming with Java, Updated Edition (Addison-Wesley, 2000) Created: 14 August 2004, Revised 4 March 2010

Inheritance and Substitutability Idealization of inheritance  Instance of "subclass" can substitute for instance of parent  Substitutability by implementing interfaces in Java as well as subclassing Abstract concept captured with two rules of thumb  is-a relation "A dog is-a mammal" sounds right  Natural for dog to inherit from mammal  has-a relation "A car is-a(n) engine" sounds wrong  Not natural to use inheritance But "a car has-a(n) engine" sounds right  Can use composition (aggregation) 1

Two Approaches to Software Reuse in OOP Inheritance  is-a relationship Useful when new software component has all behavior of existing component, plus more – extends Inheritance of just specification or of code as well Inheritance can be used if " new-thing is-a old-thing " sounds reasonable Composition (aggregation)  has-a relationship Useful when new software component builds on existing system but differs fundamentally from it Composition can be used if " new-thing has-a old-thing " sounds reasonable 2

Example Building Sets from Lists Suppose already have List data type with behavior class List { public List() {... } public void add(int) {... } public void add(int) {... } public void remove(int) {... } public void remove(int) {... } public boolean includes(int) {... } public boolean includes(int) {... } public int firstElement() {... } public int firstElement() {... }......} Wish to build Set data type  Elements are unique and unordered in set 3

Using Inheritance class Set extends List { public void add(int) {... } } Only need specify what is new  add() method overrides the one in List Everything else stays same as in List Inherits unneeded firstElement() operation Set potentially substitutable for List (undesirable) 4

Using Composition (Aggregation) class Set { public Set() {... data = new List();... } public void add(int) {... } public void remove(int) {... } public boolean includes(int) { return data.includes(int); } private List data; } Note data field of type List Redefine all operations except unneeded operation firstElement() May use List operations on data field Set not substitutable for List 5

Comparison of Inheritance and Composition Advantages of inheritance over composition  Shorter code  Increased functionality (thru polymorphism)  Sometimes less execution overhead Advantages of composition over inheritance  Easier to see and understand functionality  No "yo-yo" effect  Inappropriate operations on constituent ("parent") type hidden  Easier to change to different constituent type 6

Combining Inheritance and Composition Java API class InputStream Abstract concept of an input stream Concrete realizations differ by source of data values, each substitutable for parent  ByteArrayInputStream, FileInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream Also filters (or wrappers) for input streams that specify processing of data, both inheriting from and having InputStream component  FilterInputStream gets data from its component InputStream of any type but also substitutable for InputStream Note two orthogonal sources of variation  Data source and processing 7

Dynamic Composition An advantage of composition over inheritance  Composition: binding time  Inheritance: compile time 8

Dynamic Composition Example class Frog {public Frog() { behavior = new TadpoleBehavior(); } public void grow() // see if behavior should change { if (behavior.growUp()) { behavior = new AdultFrogBehavor(); } behavior.grow(); // behavior does actual work behavior.swim(); } private FrogBehavior behavior; } 9

Dynamic Composition Example (cont.) abstract class FrogBehavior { public void grow(); public void swim(); public boolean growUp() { return false; } } class TadpoleBehavior extends FrogBehavior { public void grow() {... } public void swim() {... } public boolean growUp() { age++; return (age > 24); } private int age = 0; } class AdultFrogBehavior extends FrogBehavior { public void grow() {... } public void swim() {... } } 10

Dynamic Composition (cont.) Frog delegates its work to FrogBehavior object Polymorphic variable behavior holds current FrogBehavior object Different FrogBehavior classes for differing behaviors (tadpole or adult) Frog object modifies behavior component when change needed (from tadpole to adult at proper age) Polymorphism means correct grow() and swim() methods called for current stage Frog object (interface) unchanged throughout life, but actual behavior changed as needed 11

Will Widespread Software Reuse Become Reality? Even with the right mechanisms, software reuse not guaranteed to occur Also need the right culture Solid reusable component libraries Guidelines for producing reusable components Appropriate training of programmers for reuse Willingness of programmers to reuse Willingness of managers to pay for development of reusable components Patience and long-term dedication to reuse 12

Acknowledgement 13 This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).” This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).”