Скачать презентацию פרק 6 DIP דוגמאות נוספות אביב תשס ה Скачать презентацию פרק 6 DIP דוגמאות נוספות אביב תשס ה

f68fa3e9a513c8d90cce95fd699fe47d.ppt

  • Количество слайдов: 19

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

 Dependency Inversion Principle ) (DIP עיקרון שינוי)היפוך( תלות מודול בשכבה מסויימת לא יהיה Dependency Inversion Principle ) (DIP עיקרון שינוי)היפוך( תלות מודול בשכבה מסויימת לא יהיה תלוי ישירות בשכבה נמוכה יותר, התלות בניהם תהיה באמצעות הפשטה. אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 2

 הגדרות לתיכון גרוע • The TNTWI-WHDI Criterion ”? -“Why’d you do it that הגדרות לתיכון גרוע • The TNTWI-WHDI Criterion ”? -“Why’d you do it that way ” “That’s not the way I would have done it • - Rigidity קשיחות. שינוי במקום מסויים ישפיע על יותר מדי מקומות נוספים. • - Fragility שבירות. שינוי במקום מסויים יגרום לליקויים במקומות בלתי צפויים. • – Immobility אי-ניידות. קשה להעביר מיישום מסויים ליישום אחר בגלל שהוא 'תפור' עבור היישום הראשון. אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 3

copy : דוגמא DIP של תוכנית פרוצדואלית בלי Structure Chart ייצוג ב output. Device copy : דוגמא DIP של תוכנית פרוצדואלית בלי Structure Chart ייצוג ב output. Device copy c c read Keyboard 4 תיכון תוכנה ד"ר ר' גלנט / י' לויאן write Printer JCT אביב תשס"ה

copy : דוגמא DIP מימוש בלי output. Device //The Copy Program void copy() { copy : דוגמא DIP מימוש בלי output. Device //The Copy Program void copy() { int c; while ((c = read. Keyboard()) != EOF) write. Printer(c); } // The “Enhanced” Copy Program enum output. Device {PRINTER, DISK}; void copy(output. Device dev) { int c; while ((c = read. Keyboard()) != EOF) if (dev == PRINTER) write. Printer(c); else write. Disk(c); } 5 copy c read Keyboard c write Printer // Copy using stdio. h #include #include Copy. h void copy() { int c; while((c = getchar()) != EOF) putchar(c); } תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה

 דוגמא: copy ייצוג ב OMD של תוכנית מונחית עצמים )לפני השימוש ב – דוגמא: copy ייצוג ב OMD של תוכנית מונחית עצמים )לפני השימוש ב – (DIP אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 6

 דוגמא: copy ) OMD לאחר השימוש ב (DIP אביב תשס דוגמא: copy ) OMD לאחר השימוש ב (DIP אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 7

copy : דוגמא (DIP )תוכנית לאחר השימוש ב // The OO Copy Program class copy : דוגמא (DIP )תוכנית לאחר השימוש ב // The OO Copy Program class IReader { public: virtual int read() = 0; }; class IWriter { public: virtual void write(char) = 0; }; class Copier { public: void copy() { int c while((c=its. IReader->read()) != EOF) its. IWriter->write(c); } }; 8 תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה

 ארכיטקטורה בשכבות ארכיטקטורה בשכבות "מבנה טוב של ארכיטקטורת תוכנה הוא: ארכיטקטורה שכבתית כאשר כל שכבה מספקת קבוצה קוהרנטית של שירותים )על ידי ממשקים מוגדרים היטב(" [Grady Booch, Object Solutions, Addison ]. 45. Wesley, 1996, p אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 9

 ארכיטקטורה שכבתית Package Structure אביב תשס ארכיטקטורה שכבתית Package Structure אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 01

 ארכיטקטורה שכבתית בלי DIP Class Structure אביב תשס ארכיטקטורה שכבתית בלי DIP Class Structure אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 11

 ארכיטקטורה שכבתית עם DIP אביב תשס ארכיטקטורה שכבתית עם DIP אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 21

 דוגמא: 'כפתור ונורה' Collaboration Diagram OMD לפני השימוש ב- DIP אביב תשס דוגמא: 'כפתור ונורה' Collaboration Diagram OMD לפני השימוש ב- DIP אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 31

' דוגמא: 'כפתור ונורה DIP- מימוש לפני השימוש ב //file “Button. h” #ifndef Button_H ' דוגמא: 'כפתור ונורה DIP- מימוש לפני השימוש ב //file “Button. h” #ifndef Button_H #define Button_H class Lamp; class Button { public : Button (Lamp& l); void detect(); bool get. Physical. State(); protected: Lamp * its. Lamp; }; #endif 14 // file Button. cpp -------#include “Button. h” #include “Lamp. h” void Button: : detect() { bool is. Button. On = get. Physical. State(); if (is. Button. On) its. Lamp->turn. On(); else its. Lamp->turn. Off(); }; // file Lamp. h #ifndef Lamp_H #define Lamp_H class Lamp { public: void turn. On(); void turn. Off(); }; #endif תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה

 דוגמא: 'כפתור ונורה' OMD עם השימוש ב- DIP אביב תשס דוגמא: 'כפתור ונורה' OMD עם השימוש ב- DIP אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 51

' דוגמא: 'כפתור ונורה DIP- מימוש עם השימוש ב // file: IButton. Server. h ' דוגמא: 'כפתור ונורה DIP- מימוש עם השימוש ב // file: IButton. Server. h #ifndef IButton. Server_H #define IButton. Server_H class IButton. Server { public: virtual void turn. On() = 0; virtual void turn. Off() = 0; }; #endif // file Button. h #ifndef IButton. H #define IButton. H class IButton. Server; class Button { public: Button(IButton. Server& a. Button. Server); void detect(); virtual bool get. State() = 0; protected: IButton. Server * its. IButton. Server; }; #endif 16 // file Button. cpp #include “Button. h” #include “IButton. Server. h” Button: : Button(IButton. Server& Button. Server): its. IButton. Server ((Button. Server *) & a. Button. Server){ } void Button: detect() { bool is. Button. On = t. State() if (is. Button. On) its. IButton. Server->turn. On(); else its. IButton. Server->turn. Off(); } תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה

' דוגמא: 'כפתור ונורה ( )המשך DIP- מימוש עם השימוש ב //File Lamp. h ' דוגמא: 'כפתור ונורה ( )המשך DIP- מימוש עם השימוש ב //File Lamp. h #ifndef Lamp_H #define Lamp_H #include “IButton. Server. h” class Lamp : public IButton. Server { public: virtual void turn. On(); virtual void turn. Off(); }; #endif // File Button. Implement. h #ifndef Button. Implement_H #define Button. Implement_H #include “Button. h” class Button. Implement : public Button { public: Button. Implementation (IButton. Server& a. Button. Server) virtual bool get. State(); }; #endif // File Button. Implement. cpp #include “Button. Implement. h” Button. Implement: : Button. Implement (IButton. Server& a. Button. Server) : Button ((Button. Server *) &a. Button. Server) {} 17 תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה

 תרשים OMD עם object adapter נדרש כאשר יש תוכנת צד שלישי שאינה תומכת תרשים OMD עם object adapter נדרש כאשר יש תוכנת צד שלישי שאינה תומכת בממשק של ה Server אביב תשס"ה JCT תיכון תוכנה ד"ר ר' גלנט / י' לויאן 81

adapter מימוש עם //File Lamp. Adapter. h #ifndef Lamp. Adapter_H #define Lamp. Adapter_H #include adapter מימוש עם //File Lamp. Adapter. h #ifndef Lamp. Adapter_H #define Lamp. Adapter_H #include “IButton. Server. h” class Lamp; class Lamp. Adapter : public IButton. Server { public: Lamp. Adapter (Lamp & a. Lamp); virtual void turn. On(); virtual void turn. Off(); Lamp * its. Lamp; }; #endif //File Lamp. Adapter. cpp #include “Lamp. Adapter. h” #include “Lamp. h” Lamp. Adapter: : Lamp. Adapter (Lamp & a. Lamp) : its. Lamp( & a. Lamp) {} Lamp. Adapter: : turn. On() {its. Lamp->on(); } Lamp. Adapter: : turn. Off() {its. Lamp->off(); } 19 //File Lamp. h #ifndef Lamp_H #define Lamp_H #include “Lamp. Adapter. h” class Lamp { public: Lamp (); virtual void on(); virtual void off(); }; #endif //File Lamp. cpp #include “Lamp. h” Lamp: : Lamp () { new Lamp. Adapter( *this); } תיכון תוכנה ד"ר ר' גלנט / י' לויאן JCT אביב תשס"ה