C++ TokensOperatorsExpressionsOperator overloadingControl statementsC++ functionsClass and objectsConstructor and destructorsOperator OverloadingType conversionsInheritanceAbstractionPolymorphismpointersInput/outputFile HandlingTemplatesException handling |
BASIC CONCEPT OF OBJECT ORIENTED PROGRAMMINGthis is necessary to understand some of the concepts used in the object oriented programming language, these are follows. BASIC CONCEPT OF OBJECT ORIENTED PROGRAMMING It is necessary to understand some of the concepts used in the object oriented programming these are follows
1. Objects In a multiple function programs, many important data items are placed as global so that they may be accessed by all the functions, each function may have its own local data. in the below figure show the relationship of data and functions in a procedure oriented program Objects: in the oops(Object oriented programming) the objects are the basic run-time entities in an object oriented system. They may be represent a person, a bank account a place or a table of data and any item that the program has to handle. They may also represent user defined such as list and vectors time. every programming problem is analyzed in terms of object and the nature of communication between the program objects should be chosen such that these match closely with the real world objects. objects take space in the memory and have an associated address like a record in pascal, or a structure in c language. Whenever The program is executed, the objects interact by the sending messages to one another. take example of customer and account are two objects in a program, Then whenever the customer object may send a message to the account object requesting for the bank balance, each object contains data, and the code to manipulate the data. The objects can interact without having to knowing details of each others data or code. It is sufficient to know the type of message accepted, and thee type of response returned by the objects. Although different authors represent them differently take example to understand
Classes: in the previous we just mentioned that objects contain data, and code to manipulate that data. The entire set of data and the code of an object can be made a user defined data type with the help of a class. in fact, objects are variables of the types class. once c class has been defined, we can create any number of objects belonging to that class. Every and each object is associated with the data of type class with which they are created. A class is a collection of objects of similar type. for example grapes, orange and apple and are members of class fruit. The classes are user defined data types and always behave like the built in types of a programming. The syntax used to create an object is not any different than the syntax used to create an integer object in C programming. take example if the fruit has been defined as a class, then the below statement
fruit apple; DataAbstraction and Encapsulation The wrapping up of data and functions into a single unit(class) is known encapsulation. Data encapsulation is the most strickly feature of a class. The data is not accessible to the outside(class) or world, and only those functions which are wrapped in the class can access it. These functions provide the interface between the object data and the program. This insulation of the data or functions from direct access by the program is called information hiding or data hiding. Abstract refers to the act of representing essential features without including the background details or explanations.classes use the concept of abstraction and defined as a list of abstract attributes such as weight, size and cost and functions to operate on these attributes. They encapsulate all the properties of the objects that are to be created. The attributes are also called data members because they hold information. The functions that operate on these data are called methods or member functions. Since the classes use the concept of data abstraction, they are known as abstract data types(ADT). Inheritance: inheritance is the process by which objects of one class acquire the properties of objects of another class. it supports the concept of hierarchical classification. take example the bird ‘robin’ is a part of the class ‘flying bird’ which is again a part of the ‘bird’ class. The principal behind this sort of division is that each derived class shares the common characteristics with the class from which it’s derived as show in fig below In OOP, the inheritance provides the idea of re-usability. This means that we can add additional features to an existing one. The new class will have the mechanism is that it.
allows the programmer to reuse a class that is almost , but not exactly, what he wants, and to class tailor in such a way that it does not introduce any undesirable side effects into the rests of the classes Note: note that each subclass defines only those features that are unique to it. without the use of classification, so each class would have to explicitly include all of its features Polymorphism: in the oops concept polymorphism is another important concept. Polymorphism a greek term, means the ability to take more than one form. An operations may exhibit different behaviour in different instances. The behaviours depends upon the type of data used in the operation. for example, consider the operation of addition. for two no., and the operation will be generate a sum. if the operands are strings, then operator to exhibit different behaviours in different instances is known operator overloading. let us take example that a single function name can be used to handled different number and different types of arguments. it’s something similar to a particular word having several different meanings depending on context. using a single function name to perform different type of tasks is know as function overloading
polymorphism plays a very important role in allowing objects having different internal structures to share the same external interface. its means that a general class of operations may be access in the same manner even though specific actions associated with each operation may different.The main role of polymorphism is extensively used in implementing inheritance. Dynamic binding: in the oops(Object oriented programming) binding refers to the linking of a procedure call to the code to be executed in response to the call. dynamic binding (late binding ) means that the code associated with a given procedure call is not known until the call at run time. It is associated with polymorphism and inheritance. then a function call associated with a polymorphic reference depends on the dynamic type of that reference. let us see in the above figure by inheritance every object will have this procedure. it is algorithm is , however unique to each object and so the draw procedure will be redefined in every class that defines the object. At the run time(dynamic) the code matching the object under current reference will be called. Message passing: An object oriented program(OOPS)Object oriented programming consists of a set of objects that communicate with each other. The process of programming in an object oriented language therefore involves the following basic steps show below:
1. creating classes that defines objects and their behaviour. |