



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




OOP concepts Basic concepts of object oriented programming are:
o Objects communicate with each other through message passing. Class The real world objects, such as television have many features and properties. For example every television is a complete unit in itself even if it is attached to some other device like DVD player it remains a television. There is an interface like buttons and remote control to operate television. All televisions have some common properties and operations. Collection of similar objects is known as class. And instances of that class are called objects. Example : Name of class – television Data – brand, model, type, volume_level, channel_number etc. Functions – switch_on(), switch_off(), change_channel(), set_volume() etc. o Class is a collection of similar objects. o Class defines all the properties (data and functions) of an object. o Class provides a well-defined interface to use the functions of that class. o A class must be complete and well-documented. o The programming code of a class should be robust. Class Object user defined data type variable of type class group of similar objects Instance of a class Class defines properties i.e. data and function members Objects hold actual values Blue print of the object Number of objects are created using class Example class and objects: Class – television with attributes as brand_name, model, size and colour. Object1 - my_tv with values as Sony, 2015, 40”, black Object2- neighbour_tv with values as Samsung, 2016, 32”, white Object3 - office_tv with values as Sony, 2014, 22”, blue Data Abstraction Abstraction means providing only the essential or relevant information and hiding the background or technical implementation details of something. Example: to drive a car one only needs to know the driving process and not the mechanics of car engine.
o Reuse of functionality o Automatically inherits attributes and methods of existing base class o Only new attributes and methods are defined in derived class o Improved code readability o Extension and modification is easier o Fast development and implementation Base class: The class whose members are inherited is called base class or parent class. Derived class : the class which is derived from the base class is called derived class or the child class. Derived class extends the functionality of base class. OOP supports different types of inheritance and access controls. Details of inheritance types and their implementation will be discussed later. Polymorphism Polymorphism means many forms. In real life situation a single person behaves differently in different situations, just like a boy is a student in school, son at home, player in playground, passenger in a bus etc. In general as a person behaves differently with different persons around, there may exist multiple implementations for single interface. A function can show different behaviour with different types of data or an operator may operate on variety of items differently. Polymorphism in OOPs means that a function or a method can handle different types of inputs and behave differently for different objects. o It allows the methods to do different things for different objects. o Polymorphism defines one interface but multiple implementations. o It allows one interface to be used for a variety of similar tasks. o One operation may show different behaviour in different instances for example ‘+’ can be used to find sum of integers, floats and complex numbers (operator overloading) o It means OOPs program can have many functions with the same name but different set of statements (known as function overloading). Dynamic Binding Binding means linking of procedure call to the code to be executed. Binding can take place at o Compile time, which is called static binding o Execution time, which is called dynamic binding In dynamic binding code is linked to the procedure call at the run time. It is associated with polymorphism and inheritance. Dynamic binding helps in writing more flexible program as the compiler can link the procedure call to procedure code after taking input from the user. Message passing
An object oriented program consists of various objects which communicate with each other through a special mechanism known as message passing. Objects can communicate by sending and receiving messages. A message for an object is a request for execution of a function or procedure. It includes invoking of related function after receiving related information. The message passing involves: o Name of the object o Name of the function- the message o Information to be sent- attributes for the called function Example: employee.salary(name) Object – employee, Message – salary, Information – name of employee Test yourself