Você está na página 1de 6

Classes and Object

Classes
A class is a way to bind the data describing an entry and its associated functions together. In C++, class makes a data type that is used to create objects of this type.

Declaration of Classes
The declaration of a class involves declaration of its four associated attributes:
1. Data Members are the data-type properties that describe the

characteristics of a class. There may be zero or more data members of any type in a class.
2. Member Functions are the set of operations that may be applied to

objects of that class. There may be zero or more member functions for a class. They are referred to as the class interface.
3. Program Access Levels that control access to members from within

the program. These access levels are private, protected, or public. Depending upon the access level of a class member, access to it is allowed or denied.
4. Class Tagname that serves as a type specifier for the class using

which objects of this class type can be created. The class specification takes place in two parts:

a)

Class definition, which describes the component members

(both data members and function members) of the class.


b)

Class method definitions which describe how certain class

member functions are implemented.

The Class Definition


The general form of a class definition is as given below: class class-name { private: [variable declarations;] [function declarations;] protected: [variable declarations;] [function declarations;] public: [variable declarations;] [function declarations;]

OBJECT ORIENTED PROGRAMMING VARIOUS PROGRAMMING PARADIGMS


A Programming Paradigm defines the methodology of designing and implementing programs using the key features and building blocks of a programming language.

PROCEDURAL PROGRAMMING
1. Procedural Programming is susceptible to design changes. In procedural programming Languages, whenever the definition of a type changes, the functions referring to this type must also be changed to reflect the change. For instance, if your program uses following structure: Struct student [ int rollno ; char name[25} int clas ; }; and the functions in the program use and manipulate this structure, e.g. void readstudent (student s1) { cout << Enter rollno ; cin >> s1.rollno ; cout << Enter name ; //

gets(name) cout << Enter class ; cin>> class ; } Now suppose that due to change in the design, the Student structure has to hold marks and grade as well i.e., structure now modifies to struct student { mt rollno ; char name [25] ; int class ; float marks ; char grade ; }; 2. Procedural Programming leads to increased time and cost overheads during design changes. As design changes lead to many modifications in the code, this leads to increased time and cost overheads at time. As budget of a software project must not exceed a limit, these overheads must be minimized and this has led to the development of new programming paradigms.

OBJECT BASED PROGRAMMING


Object based programming is a newer paradigm that implements of object oriented programming but not all. In object based programming

data and its associated meaningful functions are enclosed in one single entity a class. 1. Object based programming localizes the implementation details In object based programming, whenever there is any change in the definition of type, users interface remains unaffected. For example, consider the same student structure which will be implemented as class in object bas programming as shown below : class Student { int rollno ; char name [25] ; int class ; public: void readstudent( ) ; void dispstudent( ) ; };

OOP CONCEPTS
Object is an identifiable entity with some characteristic and behaviour. A Class is a group of objects that share common properties and relationship.

BASIC CONCEPTS OF OOP Data Abstraction


Abstraction refers to the act of representing essential features without including the background details or explanations.

Encapsulation
The wrapping up of data and operations / functions (that operate on the data) into a single unit (called class) is known as Encapsulation.

Modularity
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

Inheritance
Inheritance is the capability of one class of things to inherit capabilities properties from another class.

Polymorphism
Polymorphism is the ability for a message or data to be processed in more than one form.

Você também pode gostar