Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles
|
|
- Marianna Booker
- 6 years ago
- Views:
Transcription
1 CS 247: Software Engineering Principles Reading: none Object-Oriented Design Principles Today's Agenda Object-Oriented Design Principles - characteristics, properties, and advice for making decisions that improve the modularity of the design. OO Basics Separation of ConcernsFavour Composition over Inheritance Encapsulate what is likely Single to change Responsibility Principle Encapsulate Data Representation Liskov Substitutability Principle Abstraction (interfaces, ADTs) Principle of Least Knowledge (Law of Demeter) Reuse (through composition, inheritance) Polymorphism OO Principles Program to an Interface, not an Implementation - aka Open Closed Principle U Waterloo CS247 (Spring 2017) p.1/31 U Waterloo CS247 (Spring 2017) p.2/31 If you want to know more: References Gamma, Helm, Johnson, Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison- Wesley, Bertrand Meyer, Object-Oriented Software Construction, Prentice Hall, 1997 Robert C. Martin, Agile Software Development: Principles, Patterns, and Practices, Prentice Hall, Barbara Liskov and John Guttag, Program Development in Java, Addison-Wesley, Stanley B. Lippman, Essential C++, Addison-Wesley, U Waterloo CS247 (Spring 2017) p.3/31 Open Closed Principle Principle: A module should be open for extension but closed to modification. AKA Program to an Interface, not an Implementation Idea: Have client code depend on an abstract class (that can be extended) rather than on concrete classes. Example: Dynamic polymorphism Math Engineering Science U Waterloo CS247 (Spring 2017) p.4/31
2 Math print() "Default" Implementation Alternatively, our abstract base class may provide a default implementation that the derived classes may override. This makes it easier to derive new classes. print() Engineering print() Science print() class { }; public: virtual void print() = 0; virtual void ; protected: (); void :: {} Abstract base class can declare and define common data and operations. U Waterloo CS247 (Spring 2017) p.5/31 Inheriting Interface vs. Implementation The abstract base class designer deines what parts of a member function the derived class inherits: 1. interface (declaration) of member function e.g. printstats 2. interface and (default) overridable implementation e.g. calc 3. interface and non-overridable implementation e.g. print class { public: virtual void printstats() const = 0;//template method op virtual float ; //compute mean average void print() const; //print template transcript }; class Math : public { } class Engineering : public { } U Waterloo CS247 (Spring 2017) p.6/31 Inheritance vs. Composition Bertrand Meyer, Object-Oriented Software Construction Problem: When defining a new class that includes attributes and capabilities of an existing class, should our new class: inherit from the existing class (inheritance)? include existing class as a complex attribute (composition)? Choosing Inheritance Principle: Favour inheritance when: (1) using subtyping i.e., using the fact that a derived class can be used wherever the base class is accepted. (2) using the entire interface of an existing class. rectangle "is-a" "has-a" Math Engineering Science U Waterloo CS247 (Spring 2017) p.7/31 U Waterloo CS247 (Spring 2017) p.8/31
3 Choosing Composition Principle: Favour composition for simple (non-overriding) code reuse and extension because with composition, the components' capabilities (data and functions) can change at run-time. Delegation Delegation in object composition simulates inheritance-based method reuse. Composite object delegates operations to component object. Can pass itself as parameter, to let delegated operation refer to composite object. rectangle rectangle return rectangle->; return ; U Waterloo CS247 (Spring 2017) p.9/31 U Waterloo CS247 (Spring 2017) p.10/31 Composition and Open Close Principle The benefits of composition are maximized when the component is an abstract type an interface (in Java) or an abstract base class (in C++) that can be concretized in different ways. shape Shape The Single-Responsibility Principle Principle: Encapsulate each changeable design decision in a separate module. The Single-Responsibility Principle offers guidance on how to decompose our program into cohesive modules. Example: Based on the names of its methods, how many design decisions are implemented by this one class? return shape->; return ; Circle radius return PI radius radius; DeckOfCards hasnextcard() : bool nextcard() : Card addcard(card) removecard(card) shuffle() U Waterloo CS247 (Spring 2017) p.11/31 U Waterloo CS247 (Spring 2017) p.12/31
4 Liskov Substitutability Principle (LSP) Principle: A derived class must be substitutable for its base class. Idea: A derived class must preserve the behaviour of its base class, so that it will work with client code that uses the base class. Objects accept the base class's messages. Methods require no more than base class methods. Methods promise no less than base class methods. Client Stack Example: Bounded Stack A bounded stack is a specialized type of stack that can store only a limited number of elements. Client Stack size : int push(element) pop() : Element isempty() : bool BoundedStack maxsize : int = 255 push(element) data Element Bounded Stack U Waterloo CS247 (Spring 2017) p.13/31 U Waterloo CS247 (Spring 2017) p.14/31 Substitutability Rules Liskov, Guttag, Program Development in Java When overriding inherited virtual functions, three rules must be followed: 1) Signatures: The derived-class objects must have all of the methods of the base class, and their signatures must match. 2) Method behaviours: Calls to derived-class methods must behave like calls to the corresponding base-class methods. 3) Properties: The derived class must preserve all properties of the base class objects. LSP Signature Rules Liskov, Guttag, Program Development in Java Signatures: The derived class must support all of the methods of the base class, and their signatures must match: Parameters of overridden virtual methods must have compatible types as the parameters of the base class's methods. C++, Java: same types (otherwise redefining) The return type of an overridden virtual method must be compatible with the return type of the base-class's method. C++, Java: same type, or subtype of A derived-class method raises the same or fewer exceptions than the corresponding base-class method. U Waterloo CS247 (Spring 2017) p.15/31 U Waterloo CS247 (Spring 2017) p.16/31
5 LSP Method Rules Liskov, Guttag, Program Development in Java Method behaviours: A derived-class method maintains or weakens the precondition and maintains or strengthens the postcondition: Precondition Rule: pre_base => pre_derived LSP Property Rules Liskov, Guttag, Program Development in Java Property behaviours: The derived class must preserve all declared (and enforced) properties of the base class objects. invariants (e.g., no duplicate elements in a container type) optimized for performance (memory requirements, timing) Postcondition Rule: (pre_base && post_derived) => post_base In other words, the specification of a derived class must be stronger-than the specification of its base type. U Waterloo CS247 (Spring 2017) p.17/31 U Waterloo CS247 (Spring 2017) p.18/31 Substitutability Example class Stack { long items_; int tos_; public: Stack(); Stack(int); ~Stack(); long top() const; long pop(); virtual void push(long); }; class CountStack : public Stack { int count_; public: CountStack() : count_{0} {} void push(long); int numpushes() const; }; int CountStack::numPushes() { return count_; } void CountStack::push(long v) { Stack::push(v); count_ += 1; } Another Example Is SubstituteEntity substitutable for Entity? Entity Entity() clone() : Entity SubstituteEntity SubstituteEntity() clone() : SubstituteEntity() U Waterloo CS247 (Spring 2017) p.19/31 U Waterloo CS247 (Spring 2017) p.20/31
6 Yet Another Example Encapsulation of Components Is ChequingAccount (with a credit limit) substitutable for Account? Account balance = 0; getbalance() : double deposit(amount) withdraw(amount) : bool ChequingAccount credit limit deposit(amount) withdraw(amount) : bool invariant: balance 0 invariant: balance -credit limit add () computeterm () print () () - compute() : float - print() Information Hiding: Modular design should hide design and implementation details, including information about components. U Waterloo CS247 (Spring 2017) p.21/31 U Waterloo CS247 (Spring 2017) p.22/31 Composition and Data Encapsulation Composition and Data Encapsulation add () computeterm () print () add() get() : add () computeterm () print () add() get() : () - compute() : float - print() vs () + compute() + print() () - compute() : float - print() vs () + compute() + print() t; t->add("spring2014"); t->computeterm("spring2014"); t->print("sring2014"); t; tr; tr = t->get("spring2014"); tr->compute(); tr->print(); U Waterloo CS247 (Spring 2017) p.23/31 Composite object offers t; methods for accessing and t->add("spring2014"); t->computeterm("spring2014"); manipulating component t->print("sring2014"); information. t; tr; tr = t->get("spring2014"); tr->compute(); tr->print(); U Waterloo CS247 (Spring 2017) p.24/31
7 Another Example Component Encapsulation client code Store + settlebill (total) 1 client code Store + settlebill (total) 1 composite object Customer + pay (total) PayPal Account pay (total) CreditCard + charge (total) composite objects Customer +pay (total) PayPal Account - pay (total) 1.. CreditCard - charge (total) void Store::settlebill(float total) {... Customer->getPayPal()->getCreditCard()->charge(total);... } void Store::settlebill(float total) { Customer->pay(total); } U Waterloo CS247 (Spring 2017) p.25/31 U Waterloo CS247 (Spring 2017) p.26/31 A b: B c: C x: int m1 (D) m2 ( ) "Law" of Demeter B D C E F G H Limit of A's direct dependencies. "Law" tests encapsulation: an object "talks only to its neighbours" Method A::m1 can only call methods of A itself A s data members m1 s parameters any object constructed by A's methods You can play with yourself. You can play with your own toys (but you can't take them apart), You can play with toys that were given to you. You can play with toys you've made yourself. Peter VanRooijen In particular, an A object should not invoke methods of B objects returned by a method/function call. I U Waterloo CS247 (Spring 2017) p.27/31 BasicAccount ID balance monthlyfee = $100 + BasicAccount(balance=0) + balance () : Money + call( Date, Time, Duration ) + bill( ) + pay( amount: Money ) + printcallrecords ( mindate, maxdate ) CheapAccount monthlyfee = $30 numfreeminutes= 200 rateofcallpermin = 1 numminutes = 0 + CheapAccount(balance=0) + call( Date, Time, Duration ) + bill( ) Substitutable? CallRecord duration + CallRecord ( Date, Time, int duration ) + duration() : int + startdate() : Date + starttime() : Time 1 startdate 1 starttime Date Time day sec month min year hour + Date( day, month, year ) + Time( hour, min, second ) + day( ) : int + month( ) : string + year( ) : int + hour( ) : int + min( ) : int + sec( ) : int BasicAccount::call() creates a record of a cellphone call, recording the start date and start time of the call and the duration in minutes. BasicAccount:bill() decrements the account's balance by the monthly service fee ($100). BasicAccount::pay() increments the balance by the amount paid. calls CheapAccount::call() creates a record of a cellphone call, and updates the number of minutes (numminutes) of calls in the current month. CheapAccount:bill() decrements the account's balance by the $30 monthly service fee and by $1 for each minute of calls beyond the free 200 minutes of calls in the current month; it also resets numminutes to 0 to start recording number of call minutes for the next month. U Waterloo CS247 (Spring 2017) p.28/31
8 Favour Composition Over Inheritance BasicAccount ID balance monthlyfee = $100 + BasicAccount(balance=0) + balance () : Money + call( Date, Time, Duration ) + bill( ) + pay( amount: Money ) + printcallrecords ( mindate, maxdate ) CheapAccount monthlyfee = $30 numfreeminutes= 200 rateofcallpermin = 1 numminutes = 0 + CheapAccount(balance=0) + call( Date, Time, Duration ) + bill( ) CallRecord duration + CallRecord ( Date, Time, int duration ) + duration() : int The above design can be inefficient if a customer frequently changes the type of his or her cellphone plan. Use the principle of Favour Composition over Inheritance to restructure the design to minimize how much has to change when a customer's cellphone plan changes from a BasicAccount to a CheapAccount or vice versa. 1 startdate 1 starttime Date Time day sec month min year hour + Date( day, month, year ) + Time( hour, min, second ) + day( ) : int + month( ) : string + year( ) : int + hour( ) : int + min( ) : int + sec( ) : int U Waterloo CS247 (Spring 2017) p.29/31 Law of Demeter Which program statements violate the design principle Law of Demeter? 0 #include <vector> 1 #include "Date.h" 2 #include "Time.h" 3 4 class BasicAccount { 5 public: 6 7 void printcallrecords ( const Date &mindate, const Date &maxdate ) const; 8 9 private: 10 std::vector<callrecord> calls_; 11 static int monthlyfee_; // = $100/month 12 int balance_; 13 }; BackAccount::monthlyFee = 100; void BasicAccount::printCallRecords( const Date &mindate, const Date &maxdate) const { 19 for ( auto item : calls_ ) { 20 if ( item->startdate() >= mindate && item->startdate() <= maxdate ) { 21 std::cout << item->startdate() << " " << item->starttime(); 22 std::cout << " " << item->duration() << std::endl; 23 } 24 } 25 } U Waterloo CS247 (Spring 2017) p.30/31 Take Aways Recognition The goals underlying each design principle. That the principles are guidelines, not rules or laws. Comprehension Detect that a design violates a principle. Argue (with justification) that one design is better than another. Application Design an abstract base class. Deine whether one class is substitutable for another. Convert an inheritance relation into a composition relation. Deine whether a class encompasses more than one responsibility. U Waterloo CS247 (Spring 2017) p.31/31
CS 246: Software Abstraction and Specification. Lecture 8. Object Composition
CS 246: Software Abstraction and Specification Lecture 8 Object Composition Agenda: Object Composition Implementing Composite Objects "Law" of Demeter Reading: Eckel, Vol. 1 Ch. 14 Inheritance and Composition
More informationOO Design Principles
OO Design Principles Software Architecture VO (706.706) Roman Kern Institute for Interactive Systems and Data Science, TU Graz 2018-10-10 Roman Kern (ISDS, TU Graz) OO Design Principles 2018-10-10 1 /
More informationDesign Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles
CS 247: Software Engineering Principles Design Patterns Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch Strategy Pattern Ch 7 Adapter and Facade patterns
More informationCS 247: Software Engineering Principles. Design Patterns
CS 247: Software Engineering Principles Design Patterns Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 1 Strategy Pattern Ch 7 Adapter and Facade patterns
More informationDesign Patterns (Composite, Iterator)
CS 246: Software Abstraction and Specification Lecture 17 Design Patterns (Composite, Iterator) Reading: Head First Design Patterns U Waterloo CS246se (Spring 2011) p.1/30 Today's Agenda Design patterns:
More informationDesign Patterns (Composite)
CS 247: Software Engineering Principles Design Patterns (Composite) Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 9: Composite and Iterator Patterns
More informationOutline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism
Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Outline Subtype polymorphism Subtyping vs. subclassing Liskov Substitution Principle (LSP) Function subtyping Java subtyping Composition:
More informationDesign Patterns (Facade, Composite)
CS 247: Software Engineering Principles Design Patterns (Facade, Composite) Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 7 Adapter and Facade patterns
More informationOO Class Design Principles
3.3 Class Design Principles Single Responsibility Principle (SRP) Open/Closed Principle (OCP) Liskov Substitution Principle (LSP) a.k.a. Design by Contract Dependency Inversion Principle (DIP) Interface
More informationObject-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1
Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations
More informationn HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4
Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Announcements n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from
More informationPrinciples of Object-Oriented Design
Principles of Object-Oriented Design 1 The Object-Oriented... Hype What are object-oriented (OO) methods? OO methods provide a set of techniques for analysing, decomposing, and modularising software system
More informationObject-Oriented Concepts and Design Principles
Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation
More informationCHAPTER 5: PRINCIPLES OF DETAILED DESIGN
CHAPTER 5: PRINCIPLES OF DETAILED DESIGN SESSION II: STRUCTURAL AND BEHAVIORAL DESIGN OF COMPONENTS Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E.
More informationSummary of the course lectures
Summary of the course lectures 1 Components and Interfaces Components: Compile-time: Packages, Classes, Methods, Run-time: Objects, Invocations, Interfaces: What the client needs to know: Syntactic and
More informationInheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017
OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
CS 520 Theory and Practice of Software Engineering Fall 2017 OO design principles September 14, 2017 Today Code review and (re)design of an MVC application OO design principles Information hiding (and
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationCS 320 Introduction to Software Engineering Spring March 06, 2017
CS 320 Introduction to Software Engineering Spring 2017 March 06, 2017 Recap: types of Polymorphism Recap: types of Polymorphism Ad-hoc polymorphism (e.g., operator overloading) a + b String vs. int, double,
More informationCMPS 115 Winter 04. Class #10 (2004/02/05) Changes/Review Programming Paradigms Principles of OOD <break> Design Patterns
CMPS 115 Winter 04 Class #10 (2004/02/05) Changes/Review Programming Paradigms Principles of OOD Design Patterns Changes & Lecture 9 Takeaway Changes/Notices 2/26 may be guest after all, on design-with-frameworks
More informationCS246 Software Abstraction and Specification Final Examination
CS246 Software Abstraction and Specification ination Spring 2007 Date: 04-Aug-2007 Time: 4.00 6.30pm Permitted Aids: None 14 pages Student Name: UW Student ID: Instructions: (Read carefully before the
More informationObject-Oriented Design
Object-Oriented Design Department of Computer Engineering Lecture 12: Object-Oriented Principles Sharif University of Technology 1 Open Closed Principle (OCP) Classes should be open for extension but closed
More informationAdvanced Object Oriented PHP
CNM STEMulus Center Web Development with PHP November 11, 2015 1/17 Outline 1 2 Diamond Problem Composing vs Inheriting Case Study: Strategy Design Pattern 2/17 Definition is when a class is based on another
More informationIndex. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107
A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105
More informationCSC Advanced Object Oriented Programming, Spring Specification
CSC 520 - Advanced Object Oriented Programming, Spring 2018 Specification Specification A specification is an unambiguous description of the way the components of the software system should be used and
More informationCS 520 Theory and Practice of Software Engineering Fall 2018
Today CS 520 Theory and Practice of Software Engineering Fall 2018 Object Oriented (OO) Design Principles September 13, 2018 Code review and (re)design of an MVC application (and encapsulation) Polymorphism
More informationObject-Oriented Design
Object-Oriented Design Lecturer: Raman Ramsin Lecture 15: Object-Oriented Principles 1 Open Closed Principle (OCP) Classes should be open for extension but closed for modification. OCP states that we should
More informationWhy Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012
Why Design by Contract What s the difference with Testing? CS 619 Introduction to OO Design and Development Design by Contract Fall 2012 Testing tries to diagnose (and cure) defects after the facts. Design
More informationObject-Oriented Design
Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static
More informationPROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development
INTRODUCING API DESIGN PRINCIPLES IN CS2 Jaime Niño Computer Science, University of New Orleans New Orleans, LA 70148 504-280-7362 jaime@cs.uno.edu ABSTRACT CS2 provides a great opportunity to teach an
More informationClass-level reuse with inheritance Behavioral subtyping
Principles of Software Construction: Objects, Design, and Concurrency (Part 1: Designing Classes) Class-level reuse with inheritance Behavioral subtyping Charlie Garrod Bogdan Vasilescu School of Computer
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationThe following topics will be covered in this course (not necessarily in this order).
The following topics will be covered in this course (not necessarily in this order). Introduction The course focuses on systematic design of larger object-oriented programs. We will introduce the appropriate
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract
More informationData Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1
Design Principles Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques 2-1 Data Structures Data Structure - A systematic way of organizing and accessing
More informationPrinciples of Software Construction: Objects, Design, and Concurrency
Principles of Software Construction: Objects, Design, and Concurrency An Introduction to Object-oriented Programming, Continued. Modules and Inheritance Spring 2014 Charlie Garrod Christian Kästner School
More informationTackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance. 3.1 Introduction... 2
Department of Computer Science Tackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents
More informationLecture 7: Data Abstractions
Lecture 7: Data Abstractions Abstract Data Types Data Abstractions How to define them Implementation issues Abstraction functions and invariants Adequacy (and some requirements analysis) Towards Object
More informationAssertions. Assertions - Example
References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 11/13/2003 1 Assertions Statements about input to a routine or state of a class Have two primary roles As documentation,
More informationCSC207H: Software Design SOLID. CSC207 Winter 2018
SOLID CSC207 Winter 2018 1 SOLID Principles of Object-Oriented Design How do we make decisions about what is better and what is worse design? Principles to aim for instead of rules. e.g. there is no maximum
More informationCSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation
CSE 452: Programming Languages Data Abstraction and Object-Orientation Previous Lecture Abstraction Abstraction is the elimination of the irrelevant and the amplification of the essential Robert C Martin
More informationPatterns for polymorphic operations
Patterns for polymorphic operations Three small object structural patterns for dealing with polymorphism Alexander A. Horoshilov hor@epsylontech.com Abstract Polymorphism is one of the main elements of
More informationCHAPTER 6: CREATIONAL DESIGN PATTERNS
CHAPTER 6: CREATIONAL DESIGN PATTERNS SESSION III: BUILDER, PROTOTYPE, SINGLETON Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E. Otero For non-profit
More informationSpecial Member Functions
CS 247: Software Engineering Principles Special Member Functions Readings: Eckel, Vol. 1 Ch. 11 References and the Copy Constructor Ch. 12 Operator Overloading ( operator= ) U Waterloo CS247 (Spring 2017)
More informationIntroduction to Object-Oriented Programming
1/9 Introduction to Object-Oriented Programming Conception et programmation orientées object, B. Meyer, Eyrolles Object-Oriented Software Engineering, T. C. Lethbridge, R. Laganière, McGraw Hill Design
More informationPrinciples of Software Design. Software Engineering Alessio Gambi Saarland University
Principles of Software Design Software Engineering Alessio Gambi Saarland University The Challenge Software may live much longer than expected Software must be continuously adapted to a changing environment
More informationSpecial Member Functions. Compiler-Generated Destructor. Compiler-Generated Default Constructor. Special Member Functions
Special Member Functions CS 247: Software Engineering Principles Special Member Functions Readings: Eckel, Vol. 1 Ch. 11 References and the Copy Constructor Ch. 12 Operator Overloading ( operator= ) C++
More informationAdvanced JML Erik Poll Radboud University Nijmegen
JML p.1/23 Advanced JML Erik Poll Radboud University Nijmegen JML p.2/23 Core JML Remember the core JML keywords were requires ensures signals invariant non null pure \old, \forall, \result JML p.3/23
More informationInheritance and object compatibility
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can
More informationSoftware Engineering
Software Engineering CSC 331/631 - Spring 2018 Object-Oriented Design Principles Paul Pauca April 10 Design Principles DP1. Identify aspects of the application that vary and separate them from what stays
More informationChapter 11 Classes Continued
Chapter 11 Classes Continued The real power of object-oriented programming comes from its capacity to reduce code and to distribute responsibilities for such things as error handling in a software system.
More informationCS250 Intro to CS II. Spring CS250 - Intro to CS II 1
CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining
More informationIngegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles
Ingegneria del Software Corso di Laurea in Informatica per il Management Software quality and Object Oriented Principles Davide Rossi Dipartimento di Informatica Università di Bologna Design goal The goal
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationSpring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques
1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures:
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationOpen Closed Principle (OCP)
Open Closed Principle (OCP) Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhán Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/ SOLID Class Design Principles
More informationMaintainable Software. Software Engineering Andreas Zeller, Saarland University
Maintainable Software Software Engineering Andreas Zeller, Saarland University The Challenge Software may live much longer than expected Software must be continuously adapted to a changing environment
More informationType Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004
Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...
More informationContracts. Dr. C. Constantinides. June 5, Department of Computer Science and Software Engineering Concordia University Montreal, Canada 1/71
Contracts Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada June 5, 2018 1/71 Contracts in human affairs In human affairs we form legally
More informationChapter 8: Class and Method Design
Chapter 8: Class and Method Design Objectives Become familiar with coupling, cohesion, and connascence. Be able to specify, restructure, and optimize object designs. Be able to identify the reuse of predefined
More informationINF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes
INF 212/CS 253 Type Systems Instructors: Harry Xu Crista Lopes What is a Data Type? A type is a collection of computational entities that share some common property Programming languages are designed to
More informationThe Liskov Substitution Principle
Agile Design Principles: The Liskov Substitution Principle Based on Chapter 10 of Robert C. Martin, Agile Software Development: Principles, Patterns, and Practices, Prentice Hall, 2003 and on Barbara Liskov
More informationIntroduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes
More informationObject-oriented Programming. Object-oriented Programming
2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language
More informationIntroduction to OO Concepts
Introduction to OO Concepts Written by John Bell for CS 342, Fall 2018 Based on chapters 1, 2, and 10 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from UML Distilled
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationSoftware Engineering CSC40232: SOFTWARE ENGINEERING. Guest Lecturer: Jin Guo SOLID Principles sarec.nd.edu/courses/se2017
CSC40232: SOFTWARE ENGINEERING Guest Lecturer: Jin Guo SOLID Principles sarec.nd.edu/courses/se2017 Department of Computer Science and Engineering http://www.kirkk.com/modularity/2009/12/solid-principles-of-class-design/
More informationPRINCIPLES OF SOFTWARE DESIGN
F. Tip and M. Weintraub PRINCIPLES OF SOFTWARE DESIGN Thanks go to Andreas Zeller for allowing incorporation of his materials THE CHALLENGE 1. Software may live much longer than expected 2. Software must
More informationChapter 10 Classes Continued. Fundamentals of Java
Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an
More informationCS 215 Software Design Sample midterm solutions
Software Design Sample midterm solutions 1. The administration at Happy Valley School District is redesigning the software that manages information about its students. It has identified an abstract class
More informationProgramming Languages & Paradigms PROP HT Abstraction & Modularity. Inheritance vs. delegation, method vs. message. Modularity, cont d.
Programming Languages & Paradigms PROP HT 2011 Abstraction & Modularity Lecture 6 Inheritance vs. delegation, method vs. message Beatrice Åkerblom beatrice@dsv.su.se 2 Modularity Modularity, cont d. Modular
More informationChapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.
Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationECE 3574: Dynamic Polymorphism using Inheritance
1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:
More informationSoftware Engineering I (02161)
Software Engineering I (02161) Week 10 Assoc. Prof. Hubert Baumeister DTU Compute Technical University of Denmark Spring 2016 Last Time Project Planning Non-agile Agile Refactoring Contents Basic Principles
More informationPrinciples of Software Construction: Objects, Design and Concurrency. Polymorphism, part 2. toad Fall 2012
Principles of Software Construction: Objects, Design and Concurrency Polymorphism, part 2 15-214 toad Fall 2012 Jonathan Aldrich Charlie Garrod School of Computer Science 2012 C Garrod, J Aldrich, and
More informationTopics. Modularity and Object-Oriented Programming. Dijkstra s Example (1969) Stepwise Refinement. Modular program development
Topics Modularity and Object-Oriented Programming 申 @ 케이유티 Modular program development Step-wise refinement Interface, specification, and implementation Language support for modularity Procedural abstraction
More informationIn this Lecture you will Learn: Object Design. Information Sources for Object Design. Class Specification: Attributes
In this Lecture you will Learn: Object Design Chapter 14 How to apply criteria for good design How to design associations The impact of integrity constraints on design How to design operations The role
More informationIn this Lecture you will Learn: Design Patterns. Patterns vs. Frameworks. Patterns vs. Frameworks
In this Lecture you will Learn: Design Patterns Chapter 15 What types of patterns have been identified in software development How to apply design patterns during software development The benefits and
More informationProgrammazione. Prof. Marco Bertini
Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Introduction Why OO Development? Improved structure of software easier to: Understand Maintain Enhance Reusable
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract
More informationINF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming
More information22. Subtyping, Inheritance and Polymorphism
741 Last Week: ression Trees 742 22. Subtyping, Inheritance and Polymorphism ression Trees, Separation of Concerns and Modularisation, Type Hierarchies, Virtual Functions, Dynamic Binding, Code Reuse,
More informationLecture: Modular Design
Software Engineering Lecture: Modular Design Thomas Fritz Many thanks to Philippe Beaudoin, Gail Murphy, David Shepherd, Neil Ernst and Meghan Allen Reading! For next lecture: (all required) Composite
More informationBCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING
BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING Wednesady 23 rd March 2016 Afternoon Answer any FOUR questions out of SIX. All
More informationRefresher: Interface Specifications. ADT Documentation. Set Represented as an Array. Representation Invariant, Abstraction Function
CS 247: Software Engineering Principles Representation Invariant, Abstraction Function Refresher: Interface Specifications An interface specification is a contract between a module's provider and the client
More informationPlan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?
Plan Design principles: laughing in the face of change Perdita Stevens School of Informatics University of Edinburgh What are we trying to achieve? Review: Design principles you know from Inf2C-SE Going
More informationObject Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia
Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing
More informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
More informationOO Technology: Properties and Limitations for Component-Based Design
TDDD05 Component-Based Software OO Technology: Properties and Limitations for Component-Based Design Interfaces Design by by Contract Syntactic Substitutability Inheritance Considered Harmful Fragile Base
More informationIntroduction to Object-Oriented Programming
Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.
More informationRepresentation Invariant, Abstraction Function
CS 247: Software Engineering Principles Representation Invariant, Abstraction Function Reading: Barbara Liskov and John Guttag, Program Development in Java: Abstraction, Specification, and Object Oriented
More informationa correct statement? You need to know what the statement is supposed to do.
Using assertions for correctness How can we know that software is correct? It is only correct if it does what it is supposed to do. But how do we know what it is supposed to do? We need a specification.
More informationUNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED
UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED EXERCISE 11.1 1. static public final int DEFAULT_NUM_SCORES = 3; 2. Java allocates a separate set of memory cells in each instance
More informationGoals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming
Goals of Lecture Lecture 27: OO Design Patterns Cover OO Design Patterns Background Examples Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2001 April 24, 2001 Kenneth
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are
More informationThe Challenge. Principles of Software Design
Squircle {2 * k.radius = r.a = r.b +set_a() +resize(factor:double) Shape -position: Point = (10, 10) +area(): double +draw() +set_position(position: Point) +get_position(): Point Circle -radius: double
More informationThe Object Oriented Paradigm
The Object Oriented Paradigm Joseph Spring 7COM1023 Programming Paradigms 1 Discussion The OO Paradigm Procedural Abstraction Abstract Data Types Constructors, Methods, Accessors and Mutators Coupling
More information