Encapsulation, Data Hiding and Static Data Members

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
Learners Support Publications Classes and Objects.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
CSC241 Object-Oriented Programming (OOP) Lecture No. 6.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CITA 342 Section 1 Object Oriented Programming (OOP)
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
Operator Overloading.
Classes (Part 1) Lecture 3
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Examples of Classes & Objects
Object-Oriented Programming: Classes and Objects
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Review: Two Programming Paradigms
11.1 The Concept of Abstraction
About the Presentations
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming Using C++
Lecture 4-7 Classes and Objects
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Object Based Programming
METHODS AND BEHAVIORS AKEEL AHMED.
Object-Oriented Programming
Classes & Objects: Examples
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
Object-Oriented Programming
Object-Oriented Programming in PHP
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
CLASSES AND OBJECTS.
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Tonga Institute of Higher Education
Object-Oriented Programming Using C++
Object-Oriented Programming
Submitted By : Veenu Saini Lecturer (IT)
NAME 436.
CPS120: Introduction to Computer Science
ITE “A” GROUP 2 ENCAPSULATION.
Object Oriented Programming (OOP) Lecture No. 12
C++ Object Oriented 1.
11.1 The Concept of Abstraction
Object Oriented Programming
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Encapsulation, Data Hiding and Static Data Members

Encapsulation in C++ Bind the Data and Code together Classes are provided in C++ to bind data and code together View everything in world as objects Generalization of objects is classes Characteristics / Properties are data members and operations that can be performed by the objects / on the objects are member functions

What are Classes? Stroustrup initially named classes as structures with functions In C++, structures can have functions

Time Problem In a online examination system, each test will be scheduled for ‘x’ minutes. The student is free to take up the test on his convenience but once he starts the test, he must complete. Given the start time and the value of ‘x’ for an examination, develop an algorithm and write a ‘C++’ code for the examination system to calculate the finish time of the test.

Structural Programming for Time Problem Its also possible to write a purely procedural program in C++ Time problem shall be solved using purely structural programming in C++

Structures in C++ Can have functions in it Solution for time problem with functions in structure

Classes in C++ Similar to structures, only access specifier changes Data hiding is achieved by using access specifiers By default all members of structures in C++ has public access whereas members of classes have private access by default

Access Specifiers in C++ Three Public Private Protected

Public Access Specifier is used in the program Definition of member functions are similar to structures

Constant member functions A function becomes const when const keyword is used at the end of function’s declaration The idea of const functions is not allow them to modify the object on which they are called.  It is recommended practice to make as many functions const as possible so that accidental changes to objects are avoided.

Constant member functions Objects can also be constants Constant functions can be accessed by both constant and non-const member functions

Static Data Members Class members static using static keyword Shared by all objects of the class Shall be initialized outside the class using scope resolution operator Static data members can be referred to without referring to an object of class type but by using class name and scope resolution operator

Each object has a copy of normal variables whereas static variables are shared among the objects In figure, Variable1, Variable2 etc are normal variables

Static Member Functions can be called even if no objects of the class exist and thestatic functions are accessed using only the class name and the scope resolution operator ::. can only access static data member, other static member functions and any other functions from outside the class.