SlideShare a Scribd company logo
1 of 15
Object Oriented Programming
Objects and Classes
Object Oriented Approach

When we enters in OO approach, we
− Do not focus how problem divides into functions
− Do Focus how to divide into objects

This approach helps to model real world
− Everything in real world can be imagine to be divided
into objects
Object Oriented Approach

When we enters in OO approach, we
− Do not focus how problem divides into functions
− Do Focus how to divide into objects

This approach helps to model real world
− Everything in real world can be imagine to be divided
into objects
Objects

What kinds of things become objects in object-oriented
programs
− Depends on thinker’s imaginations
− Few Examples to take a start

Automobiles in a traffic-flow simulation

Countries in an economics model

Aircraft in an air traffic control system

Elements of the computer-user environment
− Menus
− Graphics objects (lines, rectangles, circles)
− The mouse, keyboard, disk drives, printer

Data-storage constructs
− Customized arrays
− Stacks
− Linked lists
− Binary trees

Human entities
− Employees
− Students
− Customers
− Salespeople

Collections of data
− An inventory
− A personnel file
− A dictionary

User-defined data types
− Time
− Angles
− Complex numbers
− Points on the plane

Components in computer games
− Cars in an auto race
− Positions in a board game (chess, checkers)
− Animals in an ecological simulation
− Opponents and friends in adventure games
Objects cont.
Classes

In OOP we say that objects are members of
classes

A class is thus a description of a number of
similar objects

Class serves as a plan

It specifies what data and what functions will be
included in objects of that class

Defining the class doesn’t create any objects

An object is often called an “instance” of a class.
Relationship of Class and Object
Defining Classes
Keywords private and public are access specifiers
Functions Are Public, Data Is Private
Usually the data within a class is private and the functions are public.
The data is hidden so it will be safe from accidental manipulation
The functions that operate on the data are public so they can be accessed from
outside the class.
Defining Classclass smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
Data Members
The smallobj class contains one data item or data member(somedata), which is of type int.
There can be any number of data members in a class
Member Functions
Member functions are functions that are included within a class
There are two member functions in smallobj: setdata() and showdata().
The definition of the class does not create any objects
It only describes how objects of this class will look when they are created
Using the Class and Defining the
Objectsclass smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
Defining Objects
smallobj s1, s2; //defines two objects, s1 and s2, of class smallobj
Defining an object is similar to defining a variable of any data type
Space is set aside for it in memory
An object is an instance of a class
Objects are sometimes called instance variables
Using the Objects and Calling
the Member functions
class smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
Calling Member Functions
Call the member function setdata():
s1.setdata(1066);
s2.setdata(1776);
This strange syntax is used to call a member function that is associated with a specific
object
setdata(1066); // error
Defining Objects
smallobj s1, s2;
//defines two objects, s1
and s2, of class smallobj
Using the Objects and Calling
the Member functions
class smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
Calling Member Functions
Call the member function setdata():
s1.setdata(1066);
s2.setdata(1776);
Defining Objects
smallobj s1, s2;
//defines two objects, s1
and s2, of class smallobj
A Simple Class
int main()
{
smallobj s1, s2; //define two objects of class smallobj
s1.setdata(1066); //call member function to set data
s2.setdata(1776);
s1.showdata(); //call member function to display data
s2.showdata();
return 0;
}
class smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
The Unified Modeling Language
(UML)

The UML is a graphical “language” for modeling
computer programs

UML provides a way to visualize the higher-level
organization of programs without getting in the
details of actual code.
Why do we need the UML

The trouble with code is that it’s very detailed

We need a way to see a bigger picture that:
− depicts the major parts of the program and how they work
together

UML provides this picture.

UML is a set of different kinds of diagrams
− Class diagrams

show the relationships among classes
− Object diagrams

show how specific objects relate,
− Sequence diagrams

show the communication among objects over time
− Use case diagrams

show how a program’s users interact with the program, and so on

More Related Content

Similar to Classes and objects

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
secondakay
 

Similar to Classes and objects (20)

Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptxObject Oriented Programming using C++: Ch06 Objects and Classes.pptx
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
 
Oops concept
Oops conceptOops concept
Oops concept
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
02.adt
02.adt02.adt
02.adt
 
ccc
cccccc
ccc
 
Classes1
Classes1Classes1
Classes1
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 

Recently uploaded

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
BalamuruganV28
 

Recently uploaded (20)

Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 

Classes and objects

  • 2. Object Oriented Approach  When we enters in OO approach, we − Do not focus how problem divides into functions − Do Focus how to divide into objects  This approach helps to model real world − Everything in real world can be imagine to be divided into objects
  • 3. Object Oriented Approach  When we enters in OO approach, we − Do not focus how problem divides into functions − Do Focus how to divide into objects  This approach helps to model real world − Everything in real world can be imagine to be divided into objects
  • 4. Objects  What kinds of things become objects in object-oriented programs − Depends on thinker’s imaginations − Few Examples to take a start  Automobiles in a traffic-flow simulation  Countries in an economics model  Aircraft in an air traffic control system  Elements of the computer-user environment − Menus − Graphics objects (lines, rectangles, circles) − The mouse, keyboard, disk drives, printer  Data-storage constructs − Customized arrays − Stacks − Linked lists − Binary trees  Human entities − Employees − Students − Customers − Salespeople
  • 5.  Collections of data − An inventory − A personnel file − A dictionary  User-defined data types − Time − Angles − Complex numbers − Points on the plane  Components in computer games − Cars in an auto race − Positions in a board game (chess, checkers) − Animals in an ecological simulation − Opponents and friends in adventure games Objects cont.
  • 6. Classes  In OOP we say that objects are members of classes  A class is thus a description of a number of similar objects  Class serves as a plan  It specifies what data and what functions will be included in objects of that class  Defining the class doesn’t create any objects  An object is often called an “instance” of a class.
  • 8. Defining Classes Keywords private and public are access specifiers Functions Are Public, Data Is Private Usually the data within a class is private and the functions are public. The data is hidden so it will be safe from accidental manipulation The functions that operate on the data are public so they can be accessed from outside the class.
  • 9. Defining Classclass smallobj //define a class { private: int somedata; //data member public: void setdata(int d) //member function to set data { somedata = d; } void showdata() //member function to display data { cout << “Data is “ << somedata << endl; } }; Data Members The smallobj class contains one data item or data member(somedata), which is of type int. There can be any number of data members in a class Member Functions Member functions are functions that are included within a class There are two member functions in smallobj: setdata() and showdata(). The definition of the class does not create any objects It only describes how objects of this class will look when they are created
  • 10. Using the Class and Defining the Objectsclass smallobj //define a class { private: int somedata; //data member public: void setdata(int d) //member function to set data { somedata = d; } void showdata() //member function to display data { cout << “Data is “ << somedata << endl; } }; Defining Objects smallobj s1, s2; //defines two objects, s1 and s2, of class smallobj Defining an object is similar to defining a variable of any data type Space is set aside for it in memory An object is an instance of a class Objects are sometimes called instance variables
  • 11. Using the Objects and Calling the Member functions class smallobj //define a class { private: int somedata; //data member public: void setdata(int d) //member function to set data { somedata = d; } void showdata() //member function to display data { cout << “Data is “ << somedata << endl; } }; Calling Member Functions Call the member function setdata(): s1.setdata(1066); s2.setdata(1776); This strange syntax is used to call a member function that is associated with a specific object setdata(1066); // error Defining Objects smallobj s1, s2; //defines two objects, s1 and s2, of class smallobj
  • 12. Using the Objects and Calling the Member functions class smallobj //define a class { private: int somedata; //data member public: void setdata(int d) //member function to set data { somedata = d; } void showdata() //member function to display data { cout << “Data is “ << somedata << endl; } }; Calling Member Functions Call the member function setdata(): s1.setdata(1066); s2.setdata(1776); Defining Objects smallobj s1, s2; //defines two objects, s1 and s2, of class smallobj
  • 13. A Simple Class int main() { smallobj s1, s2; //define two objects of class smallobj s1.setdata(1066); //call member function to set data s2.setdata(1776); s1.showdata(); //call member function to display data s2.showdata(); return 0; } class smallobj //define a class { private: int somedata; //data member public: void setdata(int d) //member function to set data { somedata = d; } void showdata() //member function to display data { cout << “Data is “ << somedata << endl; } };
  • 14. The Unified Modeling Language (UML)  The UML is a graphical “language” for modeling computer programs  UML provides a way to visualize the higher-level organization of programs without getting in the details of actual code.
  • 15. Why do we need the UML  The trouble with code is that it’s very detailed  We need a way to see a bigger picture that: − depicts the major parts of the program and how they work together  UML provides this picture.  UML is a set of different kinds of diagrams − Class diagrams  show the relationships among classes − Object diagrams  show how specific objects relate, − Sequence diagrams  show the communication among objects over time − Use case diagrams  show how a program’s users interact with the program, and so on