PIMPL Idiom Encapsulating Implementation. Forward Declaration Revisited forward class declaration – names the class, does not provide definition class.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Classes and Objects Systems Programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 16: Classes and Data Abstraction Outline 16.1Introduction.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 7: Methods.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Abstract Data Types and Encapsulation Concepts
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
INF 523Q Chapter 5: Enhancing Classes. 2 b We can now explore various aspects of classes and objects in more detail b Chapter 5 focuses on: object references.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Programming Languages and Paradigms Object-Oriented Programming.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
CS212: Object Oriented Analysis and Design Lecture 5: Classes and Objects - II.
Learners Support Publications Classes and Objects.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Object-Based Programming Mostly Review. Objects Review what is object? class? member variables? member functions? public members? private members? friend.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CLASSES : A DEEPER LOOK Chapter 9 Part I 1. 2 OBJECTIVES In this chapter you will learn: How to use a preprocessor wrapper to prevent multiple definition.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object-Oriented Programming Chapter Chapter
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 13: Overloading and Templates. Objectives In this chapter, you will – Learn about overloading – Become familiar with the restrictions on operator.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Programming Techniques Classes II Important Class Features Spring 2009.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
TK1924 Program Design & Problem Solving Session 2011/2012
Eine By: Avinash Reddy 09/29/2016.
CSE691 Software Models and Analysis.
Chapter 5: Enhancing Classes
Abstract Data Types and Encapsulation Concepts
Chapter 16: Classes and Data Abstraction
Review: Two Programming Paradigms
11.1 The Concept of Abstraction
Object-Oriented Programming Using C++
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Interfaces and Inner Classes
Lecture 4-7 Classes and Objects
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Chapter 9 Classes: A Deeper Look, Part 1
Packages and Interfaces
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
Parameter Passing Actual vs formal parameters
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
Object-Oriented Programming Using C++
Classes and Objects Systems Programming.
SPL – PS3 C++ Classes.
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Introduction to Classes and Objects
Presentation transcript:

PIMPL Idiom Encapsulating Implementation

Forward Declaration Revisited forward class declaration – names the class, does not provide definition class MyClass; –allows compiler to do elementary type checking –simplifies header files forward class declaration specifies incomplete type: may only declare pointers and references elaborated type specifier: forward class combined with pointer/reference declaration –have to be mentioned every pointer/reference declaration class MyClass *p; class Myclass &r; 2

Nested Classes nested class is an class declared inside another class inner class –scope is the outer class scope limitation is the primary purpose for this construct –if object or method is mentioned outside of outer class, need to resolve the scope –can be private or public –can be forward declared and then defined outside if forward declared, the forward declaration should be inside the outer class definition –has access to private/public members of outer class –outer class has no access to private/public members of inner class 3

PIMPL C++ does not provide ways to hide class implementation details/data: private part has to be declared –clients include header file with class definition: exposed to implementation pointer to implementation (PIMPL) idiom: aka opaque pointer, d-pointer, cheshire cat idiom –in private (implementation) section of class provide reference (pointer) to actual implementation –when interface methods are invoked, invoke corresponding implementation methods using the pointer –actual implementation class is defined and implemented in separately 4

PIMPL (cont) terms: –handle – class with exposed interface –body – implementation class specifics –body needs to be forward declared –body is dynamically allocated – need to implement big three –good practice to nest body inside handle advantages –encapsulates implementation, allows body modification without need to modify handle –speeds up compilation, provides binary compatibility could be used in Memento and Bridge design pattern 5