SlideShare una empresa de Scribd logo
1 de 17
C++ : наследование, часть 2 Дмитрий Штилерман, Рексофт
Краткое содержание второй части ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Интерфейсы и реализация класса ,[object Object],[object Object],[object Object],[object Object]
Public & protected interface -  пример class Shape  {   public:    virtual void redraw() = 0;   protected:   void default_redraw();  }; class Tool  {   public:   void applyTo(Shape* pShape)   {/*…*/ pShape->redraw();}  }; class Rectangle : public Shape  {   public:   virtual void redraw()   {/*…*/ default_redraw();}  }; ,[object Object],[object Object]
Public & protected interface -  обозначения ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Public inheritance  class B  {   public: void f_public();   protected: void f_protected();  }; class D : public B  {   public: void g_public();   protected: void g_protected();  }; ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Public и  protected  интерфейсы  B  добавляются в соответствующие интерфейсы  D.
Protected inheritance  class B  {   public: void f_public();   protected: void f_protected();  }; class D : protected B  {   public: void g_public();   protected: void g_protected();  }; ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Public и  protected  интерфейсы  B  добавляются в  protected  интерфейс  D.
Private inheritance  class B  {   public: void f_public();   protected: void f_protected();  }; class D : private B  {   public: void g_public();   protected: void g_protected();  }; ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Public и  protected  интерфейсы  B  становятся частью реализации  D.
Когда какое наследование  возможно  использовать? ,[object Object],[object Object],[object Object]
Почему обычно  не нужно  использовать  наследование, отличное от  public? ,[object Object],[object Object],[object Object],[object Object]
Отношение “has-a” - к омпозиция (aggregation) class Caption {…}; class Label {…}; class Button {…}; class MessageBox  {   Caption m_caption;   Label m_label;   Button m_buttonOK;   Button m_buttonCancel;   }; ,[object Object],[object Object],[object Object]
Отношени е  “is-implemented-by” - делегирование (delegation) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],class A  {   B m_b;   void f()   {m_b.f();}   void g()   {m_b.g();}  }; class B  {   public:   void f()   {…}   void g()   {…}  };
И золяция ( insulation ) ,[object Object],[object Object],[object Object],[object Object],//  Файл  gadget.h class GadgetImpl; class Gadget  {   private:   GadgetImpl* m_pImpl;   public:   Gadget();    void f();  }; //  Файл  gadget.cpp #include “gadget.h” class GadgetImpl  {   public:   void f() {…}  }; Gadget::Gadget()  {m_pImpl = new GadgetImpl;}  void Gadget::f()  {m_pImpl->f();}
P rivate  inheritance  как инкапсуляция базового класса ,[object Object],[object Object],[object Object],class A : private B  {   void f()   {B::f();}   void g()   {B::g();}  }; class B  {   public:   void f()   {…}   protected:    void g()   {…}  };
P rivate  inheritance  как упаковка общей части реализации ,[object Object],[object Object],[object Object],[object Object],class GadgetBase  {   protected:   GadgetBase();   void f()   {/*  Очень умный алгоритм  */}  }; template<class T> class Gadget : private GadgetBase  {   public:   void f()   {GadgetBase::f();}  };
Подведение итогов ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Продолжение в следующей серии ,[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

Similar a OO Design with C++: 2. Inheritance, part 2

OO Design with C++: 1. Inheritance, part 1
OO Design with C++: 1. Inheritance, part 1OO Design with C++: 1. Inheritance, part 1
OO Design with C++: 1. Inheritance, part 1Dmitry Stillermann
 
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanie
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanieCisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanie
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanieMichael Ganschuk
 
Обеспечение безопасности web приложений
Обеспечение безопасности web приложенийОбеспечение безопасности web приложений
Обеспечение безопасности web приложенийSQALab
 
Minsk Web Appl 190509
Minsk Web Appl 190509Minsk Web Appl 190509
Minsk Web Appl 190509sef2009
 
IBM Jazz - A New Approach For Software Development (In Russian)
IBM Jazz - A New Approach For Software Development (In Russian)IBM Jazz - A New Approach For Software Development (In Russian)
IBM Jazz - A New Approach For Software Development (In Russian)Alexander Klimov
 
Jazz – открытая платформа разработки ПО
Jazz – открытая платформа разработки ПОJazz – открытая платформа разработки ПО
Jazz – открытая платформа разработки ПОSQALab
 
Управление рисками ИБ: отдельные практические аспекты
Управление рисками ИБ: отдельные практические аспектыУправление рисками ИБ: отдельные практические аспекты
Управление рисками ИБ: отдельные практические аспектыAleksey Lukatskiy
 
Minsk Jazz 190509 Templ
Minsk Jazz 190509 TemplMinsk Jazz 190509 Templ
Minsk Jazz 190509 Templsef2009
 
Customer Profiling&Targeted Advertisement
Customer Profiling&Targeted AdvertisementCustomer Profiling&Targeted Advertisement
Customer Profiling&Targeted Advertisement2tique
 
Social Bookmarks, Folksonomies–Complex Networks
Social Bookmarks, Folksonomies–Complex NetworksSocial Bookmarks, Folksonomies–Complex Networks
Social Bookmarks, Folksonomies–Complex NetworksOleg Nazarevych
 
тупицын Ec2 Rootconf2009
тупицын Ec2 Rootconf2009тупицын Ec2 Rootconf2009
тупицын Ec2 Rootconf2009Liudmila Li
 
vSphere Launch Business Keynote - Москва, 26 мая
vSphere Launch Business Keynote - Москва, 26 маяvSphere Launch Business Keynote - Москва, 26 мая
vSphere Launch Business Keynote - Москва, 26 маяAnton Antich
 
Java For Digitally Signing Documents In Web Book - Svetlin Nakov
Java For Digitally Signing Documents In Web Book - Svetlin NakovJava For Digitally Signing Documents In Web Book - Svetlin Nakov
Java For Digitally Signing Documents In Web Book - Svetlin NakovSvetlin Nakov
 
IP в телевидении или телевидение в IP?
IP в телевидении или телевидение в IP?IP в телевидении или телевидение в IP?
IP в телевидении или телевидение в IP?2tique
 
Упаковка и развертывание программ на perl под debian‎
Упаковка и развертывание программ на perl под debian‎Упаковка и развертывание программ на perl под debian‎
Упаковка и развертывание программ на perl под debian‎mayperl
 
Reputation Management in Social Media
Reputation Management in Social MediaReputation Management in Social Media
Reputation Management in Social MediaHOSHVA PR
 

Similar a OO Design with C++: 2. Inheritance, part 2 (20)

OO Design with C++: 1. Inheritance, part 1
OO Design with C++: 1. Inheritance, part 1OO Design with C++: 1. Inheritance, part 1
OO Design with C++: 1. Inheritance, part 1
 
Unittests
UnittestsUnittests
Unittests
 
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanie
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanieCisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanie
Cisco collaboration. 8_oktiabria_biznes-trek_litsenzirovanie
 
Обеспечение безопасности web приложений
Обеспечение безопасности web приложенийОбеспечение безопасности web приложений
Обеспечение безопасности web приложений
 
Minsk Web Appl 190509
Minsk Web Appl 190509Minsk Web Appl 190509
Minsk Web Appl 190509
 
IBM Jazz - A New Approach For Software Development (In Russian)
IBM Jazz - A New Approach For Software Development (In Russian)IBM Jazz - A New Approach For Software Development (In Russian)
IBM Jazz - A New Approach For Software Development (In Russian)
 
Jazz – открытая платформа разработки ПО
Jazz – открытая платформа разработки ПОJazz – открытая платформа разработки ПО
Jazz – открытая платформа разработки ПО
 
Управление рисками ИБ: отдельные практические аспекты
Управление рисками ИБ: отдельные практические аспектыУправление рисками ИБ: отдельные практические аспекты
Управление рисками ИБ: отдельные практические аспекты
 
Minsk Jazz 190509 Templ
Minsk Jazz 190509 TemplMinsk Jazz 190509 Templ
Minsk Jazz 190509 Templ
 
Customer Profiling&Targeted Advertisement
Customer Profiling&Targeted AdvertisementCustomer Profiling&Targeted Advertisement
Customer Profiling&Targeted Advertisement
 
Social Bookmarks, Folksonomies–Complex Networks
Social Bookmarks, Folksonomies–Complex NetworksSocial Bookmarks, Folksonomies–Complex Networks
Social Bookmarks, Folksonomies–Complex Networks
 
Hackday Ml
Hackday MlHackday Ml
Hackday Ml
 
тупицын Ec2 Rootconf2009
тупицын Ec2 Rootconf2009тупицын Ec2 Rootconf2009
тупицын Ec2 Rootconf2009
 
vSphere Launch Business Keynote - Москва, 26 мая
vSphere Launch Business Keynote - Москва, 26 маяvSphere Launch Business Keynote - Москва, 26 мая
vSphere Launch Business Keynote - Москва, 26 мая
 
kakvo e sniffer
kakvo e snifferkakvo e sniffer
kakvo e sniffer
 
Java For Digitally Signing Documents In Web Book - Svetlin Nakov
Java For Digitally Signing Documents In Web Book - Svetlin NakovJava For Digitally Signing Documents In Web Book - Svetlin Nakov
Java For Digitally Signing Documents In Web Book - Svetlin Nakov
 
IP в телевидении или телевидение в IP?
IP в телевидении или телевидение в IP?IP в телевидении или телевидение в IP?
IP в телевидении или телевидение в IP?
 
за Ruby
за Rubyза Ruby
за Ruby
 
Упаковка и развертывание программ на perl под debian‎
Упаковка и развертывание программ на perl под debian‎Упаковка и развертывание программ на perl под debian‎
Упаковка и развертывание программ на perl под debian‎
 
Reputation Management in Social Media
Reputation Management in Social MediaReputation Management in Social Media
Reputation Management in Social Media
 

Más de Dmitry Stillermann

Как расти самому, помогая расти другим — практическое применение Management T...
Как расти самому, помогая расти другим — практическое применение Management T...Как расти самому, помогая расти другим — практическое применение Management T...
Как расти самому, помогая расти другим — практическое применение Management T...Dmitry Stillermann
 
OO Design with C++: 4. Design Principles, part 1
OO Design with C++: 4. Design Principles, part 1OO Design with C++: 4. Design Principles, part 1
OO Design with C++: 4. Design Principles, part 1Dmitry Stillermann
 
OO Design with C++: 5. Design Principles, part 2
OO Design with C++: 5. Design Principles, part 2OO Design with C++: 5. Design Principles, part 2
OO Design with C++: 5. Design Principles, part 2Dmitry Stillermann
 
OO Design with C++: 3. Inheritance, part 3
OO Design with C++: 3. Inheritance, part 3OO Design with C++: 3. Inheritance, part 3
OO Design with C++: 3. Inheritance, part 3Dmitry Stillermann
 

Más de Dmitry Stillermann (6)

DiSC Model in Practice
DiSC Model in PracticeDiSC Model in Practice
DiSC Model in Practice
 
Как расти самому, помогая расти другим — практическое применение Management T...
Как расти самому, помогая расти другим — практическое применение Management T...Как расти самому, помогая расти другим — практическое применение Management T...
Как расти самому, помогая расти другим — практическое применение Management T...
 
OO Design with C++: 4. Design Principles, part 1
OO Design with C++: 4. Design Principles, part 1OO Design with C++: 4. Design Principles, part 1
OO Design with C++: 4. Design Principles, part 1
 
OO Design with C++: 5. Design Principles, part 2
OO Design with C++: 5. Design Principles, part 2OO Design with C++: 5. Design Principles, part 2
OO Design with C++: 5. Design Principles, part 2
 
OO Design with C++: 3. Inheritance, part 3
OO Design with C++: 3. Inheritance, part 3OO Design with C++: 3. Inheritance, part 3
OO Design with C++: 3. Inheritance, part 3
 
OO Design with C++: 0. Intro
OO Design with C++: 0. IntroOO Design with C++: 0. Intro
OO Design with C++: 0. Intro
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

OO Design with C++: 2. Inheritance, part 2

Notas del editor

  1. Public vs. protected interface - two types of clients {part. Meyers1.41}. Containment as &amp;quot;has-a&amp;quot; or &amp;quot;is-implemented-via&amp;quot; relationship {Meyers1.40} Private inheritance - reasons of use instead of containment {Meyers1.42}