OOP (Object Oriented Programming)

 

  Introduction to Object Oriented 

Programming

What is (OOP)?

OOP stands for Object-Oriented Programming. Object-oriented programming is about creating objects that contain both data and functions.

Object-oriented programming has several advantages over procedural programming:

  1. OOP is faster and easier to execute.
  2. OOP provides a clear structure for the programs.
  3. OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug
  4. OOP makes it possible to create full reusable applications with less code and shorter development time.

Basic Concepts in Object-Oriented Programming

  • Classes -- Basic template for creating objects
  • Objects – Basic run-time entities
  • Data Abstraction & Encapsulation – Wrapping data and functions into a single unit
  • Inheritance – Properties of one class can be inherited into others
  • Polymorphism – Ability to take more than one forms


Object-Oriented Programming Topics:












Classes And Object

Object -- an encapsulation of data along with functions that act upon that data.

An object consists of:

  • Name -- the variable name we give it
  • Member data -- the data that describes the object
  • Member functions -- behavior aspects of the object

Class -- a blueprint for objects. A class is a user-defined type that describes what a certain type of object will look like. A class description consists of a declaration and a definition. Usually these pieces are split into separate files.


 Class syntax Defination:



Create a Class

      To create a class, use the class keyword:

      Create a class called  "MyClass":


Create a Object

·         In C++, an object is created from a class. We have already created the class named MyClass, so now we can use this to create objects.

  • To create an object of MyClass, specify the class name, followed by the object name.
  • To access the class attributes (myNum and myString), use the dot syntax (.) on the object:




C++ Class Methods

There are two ways to define functions that belongs to a class:

  1.          Inside class definition
  2.          Outside class definition


InSide Class



Outside  Class



Post a Comment

0 Comments

Close Menu