אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 4 LSP.

Slides:



Advertisements
Similar presentations
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Advertisements

1 Data Structures - CSCI 102 CS102 C++ Operator Overloading Prof Tejada.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
5/17/2015 OO Design: Liskov Substitution Principle 1.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,
1 Inheritance Concepts n Derive a new class (subclass) from an existing class (base class or superclass). n Inheritance creates a hierarchy of related.
More Inheritance and LSP CS340100, NTHU Yoshi. More about Inheritance Reuse? – Q1: 你有沒有程式 ” 砍掉重練 ” 的經驗 ? – Q2: 你有沒有 ” 再造輪子 ” 的經驗 ? class Rectangle – Firstly,
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 10 Packages.
Typing Issues and LSP Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Readability (Java vs. Pearl) Catching errors.
תרגול חזרה. מבנה האובייקט תאר את מבנה האובייקט כולל מבנה טבלאות הפונקציות הוירטואליות עבור התכנית הבאה struct A { int x; virtual void a() {}; }; struct.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 תיכון מערכות תוכנה להנדסה ופיתוח פרוייקט אישי Software Design.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 13 Case Study: Weather Station.
אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 9 נקודות חשובות בתרגיל 10 Guarded Operation.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 6 DIP דוגמאות נוספות.
1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 11 Statecharts תכונות מתקדמות.
Typing Issues and LSP David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Reliability Catching errors early Readability.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 12 אינטרקציה בין statecharts של אובייקטים שונים דוגמא : Dishwasher.
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכורות שמורות 1 פרק 3 OCP.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 7 ISP דוגמא נוספת.
2-4 tree k=2 Each node has 2,3,or 4 children. Delete delete(14,T)
תוכנה 1 תבנית העיצוב Observer 1 שחר מעוז בית הספר למדעי המחשב אוניברסיטת תל אביב.
CSc 335: Three More OO Design Principles
Design II Today: Design Principles…can we define them intro.12.ppt CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger.
1 OO Design Principles Project Group eXtreme Programming Md. Abul Bashar 07/09/2004.
Abstract Classes 1. Objectives You will be able to: Say what an abstract class is. Define and use abstract classes. 2.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
3-4 Lesson 3-4 Example 1 Use the formula A = ℓ w to solve for ℓ, length. The area of the rectangle is 72 square yards. Its width is 9 yards. What is the.
More Design. Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Design Principles iwongu at gmail dot com.
Software Design Principles
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
CS1201: Programming Language 2 Classes and objects Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
1. Perspectives on Design Principles – Semantic Invariants and Design Entropy Catalin Tudor 2.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
C++ Programming: chapter 7 – inheritence 2014, Spring Pusan National University Ki-Joune Li 1.
עקרונות תכנות מונחה עצמים תרגול 10: Generics. Outline  Generic classes  Generics & Inheritance  Wild Cards  Case study: Generic Graph.
Test Code Patterns How to design your test code. 2 Testing and Inheritance Should you retest inherited methods? Can you reuse superclass tests for inherited.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Abstract Classes 1. Objectives You will be able to: Say what an abstract class is. Define and use abstract classes. 2.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Unified Modeling Language
SW Design Principle YoungSu, Son. Microsoft MVP EvaCast Study Leader Devpia Architecture Sysop.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 5 תרשימי מצבים Statecharts למחלקות תגובתיות Reactive Classes הקדמה ודוגמא.
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
Object Oriented Programming
More Design Heuristics
Access Functions and Friend Functions
Object Oriented Programming
Inheritance class TwoDShape { private double width;
Advanced Program Design with C++
Object Oriented Programming
Introduction to Classes
EECE 310: Software Engineering
Object Oriented Programming
Reserved Words.
Introduction to Classes
תרגול מס' 11 הורשה פולימורפיזם.
Introduction to Programming
CS1201: Programming Language 2
Continued from last class
Liskov Substitution Principle (LSP)
Presentation transcript:

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 4 LSP

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 2 Liskov Substitution Principle (LSP) עקרון ההחלפה של ליסקוב קליינט המשתמש ב-pointer או ב-reference למחלקת בסיס, לא צריך לדעת לאיזה תת- מחלקה האובייקט שייך ההתנהגות של הבנים צריכה להיות דומה לשל האבא

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 3 דוגמא ל-LSP מלבן וריבוע

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 4 מלבן וריבוע - UML

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 5 מלבן וריבוע – קוד (1) class Rectangle { public: virtual void setWidth(double aWidth) {width= aWidth;} virtual void setHeight(double aHeight){height=aHeight;} double getHeight() const {return height;} double getWidth() const {return width;} private: double height; double width; };

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 6 מרובע וריבוע – קוד (2) class Square : Rectangle { public: void setWidth(double aWidth) { Rectangle::setWidth(aWidth); Rectangle::SetHeight(aWidth); } void setHeight(double aHeight) { Rectangle::setWidth(aHeight); Rectangle::SetHeight(aHeight); } };

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 7 הבעיה: מה מצפה הקליינט שיקרה בקריאה לפונקציה הבאה עם אובייקט Square? void g(Rectangle& r) { r.setWidth(5); r.setHeight(4); assert(r.GetWidth()*r.GetHeight() ==20); }

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 8 פתרון הבעיה על-פי LSP

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 9 דוגמא ל-LSP Set

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 10 Bounded and Unbounded Set

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 11 Bounded and Unbounded Set template class Set { public: virtual void add(const T&)=0; virtual void delete_(const T&)=0; virtual bool isMember(const T&) const=0; }; template void printSet(const Set & s) { for (iterator i(s); i; i++) cout << (*i) << endl; }

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 12 Bounded, Unbounded, Persistent Set

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 13 Persistent Set template void PersistentSet::add(const T& t) { // throw bad_cast PersistentObject& p = dynamic_cast (t); itsThirdPartyPersistentSet->add(p); }

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 14 Bounded, Unbounded, Persistent Set Liskov Compliant

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 15 Bounded, Unbounded, Persistent Set Liskov Compliant

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 16 שינויים מותרים ואסורים ב- State Chart של מחלקה יורשת (בעקבות LSP) מותר להוסיף מצבים ומעברים. מותר לשנות את הפעילות במעברים. אסור לשנות או לבטל יציאה ממצב, אך מותר לשנות את היעד. מותר להוסיף 'מצבי-אח' ו'מצבי-בנים', אך לא לשנות או להוסיף 'מצבי-אב'.

אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 17 דוגמא ל-State-Chart