SlideShare une entreprise Scribd logo
1  sur  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]

Contenu connexe

Similaire à 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
 
Minsk Web Appl 190509
Minsk Web Appl 190509Minsk Web Appl 190509
Minsk Web Appl 190509sef2009
 
Обеспечение безопасности web приложений
Обеспечение безопасности web приложенийОбеспечение безопасности web приложений
Обеспечение безопасности web приложенийSQALab
 
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
 

Similaire à 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
 
Minsk Web Appl 190509
Minsk Web Appl 190509Minsk Web Appl 190509
Minsk Web Appl 190509
 
Обеспечение безопасности web приложений
Обеспечение безопасности web приложенийОбеспечение безопасности web приложений
Обеспечение безопасности web приложений
 
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
 

Plus 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
 

Plus 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
 

Dernier

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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

Notes de l'éditeur

  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}