access control in inheritance
play

Access Control in Inheritance Base Part of Object From Outside the - PDF document

10. Inheritance: Encapsulation & Access private, public & protected members class Manager : public Employee { class Director : public Manager { Employee* managed_list; ... protected: void fn(......) int level; { public: level =


  1. 10. Inheritance: Encapsulation & Access private, public & protected members class Manager : public Employee { class Director : public Manager { Employee* managed_list; ... protected: void fn(......) int level; { public: level = UPPER_MANAGEMENT ;//OK int getLevel(); groupsize = }; managed_list.size(); // ERROR getLevel(); // OK } }; Director laura; laura.getLevel(); // OK laura.level = UPPER_MANAGEMENT; // ERROR

  2. Access Control in Inheritance Base Part of Object From Outside the Object Derived Part of Object - Private member - Protected member - Public member Inheritance: private, public & protected class Manager : public Employee {...}; class WindowWDlg : private Dialog {...}; public Inheritance: • Truly expresses a “is-a” relationship protected Inheritance : • Expresses inheritance for data reuse and not behavior reuse • This is better modeled as Containment.

  3. Inheritance Control - Example class Employee {...}; class Manager : public Employee {...}; class Supervisor : private Employee {...}; void SecurityCheck(const Employee&); Employee bruce; SecurityCheck(bruce); // OK Manager nancy; SecurityCheck(nancy); // OK Supervisor susan; SecurityCheck(susan); // ERROR Lab Work: Details provided on-line.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend