Chapter: Object Oriented Programming(OOP) : Basic Characteristics of OOP

Data Hiding

Object Oriented Programming(OOP) - Basic Characteristics of OOP

DATA HIDING

 

         With data hiding

         accessing the data is restricted to authorized functions

         “clients” (e.g., main program) can’t muck with the data directly

         this is done by placing the data members in the private section

         and, placing member functions to access & modify that data in the public section

         So, the public section

 

         includes the data and operations that are visible, accessible, and useable by all of the clients that have objects of this class

 

         this means that the information in the public section is “transparent”; therefore, all of the data and operations are accessible outside the scope of this class

 

         by default, nothing in a class is public!

         The private section

         includes the data and operations that are not visible to any other class or client

 

         this means that the information in the private section is “opaque” and therefore is inaccessible outside the scope of this class

 

         the client has no direct access to the data and must use the public member functions

 

         this is where you should place all data to ensure the memory’s integrity

         The good news is that

 

         member functions defined in the public section can use, return, or modify the contents of any of the data members, directly

 

         it is best to assume that member functions are the only way to work with private data

 

         (there are “friends” but don’t use them this term)

         Think of the member functions and private data as working together as a team

 

         Notice, that the display_all function can access the private my_list and num_of_videos members, directly

 

         without an object in front of them!!!

         this is because the client calls the display_all function through an object

object.display_all();

so the object is implicitly available once we enter “class scope

 

         In reality, the previous example was misleading. We don’t place the implementation of functions with this this class interface

 

         Instead, we place them in the class implementation, and separate this into its own file

•   Class Interface:              list.h

class list {

public:

int display_all()

•••

};

         list.h can contain:

         prototype statements

         structure declarations and definitions

         class interfaces and class declarations

include other files

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Basic Characteristics of OOP : Data Hiding |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.