Asian Journal of Computer Science And Information Technology 7: 3 July (2017) 68 –71. Contents lists available at www.innovativejournal.in

Asian Journal of Computer Science And Information Technology

Journal Homepage: http://innovativejournal.in/ajcsit/index./ajcsit

VIRTUAL BASE CLASS, OVERLOADING AND OVERRIDING DESIGN PATTERN IN OBJECT ORIENTED PROGRAMMING WITH C++

Dr. Ashok Vijaysinh Solanki

Assistant Professor, College of Applied Sciences and Professional Studies, Chikhli

ARTICLE INFO ABSTRACT Corresponding Author: The objective of this research paper is to discuss prime concept Dr. Ashok Vijaysinh Solanki of inheritance in object oriented programming. Inheritance play major role in Assistant Professor, College of design pattern of modern programming concept. In this research paper I Applied Sciences and Professional explained about inheritance and reusability concepts of oops. Since object Studies, Chikhli oriented concepts has been introduced in modern days technology it will be assist to creation of reusable software. Inheritance and polymorphism play Key Words: Inheritance; vital role for code reusability. OOPs have evolved to improve the quality of the Encapsulation; Polymorphism; programs. I also discuss about the relationship between , Early binding; Late binding. and run-time polymorphism. Key focus of this research paper is to discuss new approach of inheritance mechanism which helps to solve encapsulation issues. Through virtual base class concept we explore the relationship and setup connection between code reusability and inheritance. Paper explained virtual base class, early binding and late binding concepts DOI:http://dx.doi.org/10.15520/ using coding demonstration. ajcsit.v7i3.63 ©2017, AJCSIT, All Right Reserved. I INTRODUCTION Object oriented programming model is modern such as hierarchical and multiple inheritances which is practical approach and it is important programming known as pure hybrid inheritance. methodology that helps to develop modular design and II Literature Survey maximum utilization of software reusability concepts. In literature survey I, covered three major areas that is Object oriented fundamental helps us to reduce overloading, overriding and virtual base classes. With maintenance cost, reliability improvement, reusability of respect to literature review there has been lot research existing code and flexibility approach with the help of data done on oops. encapsulation. In object oriented paradigm encapsulation Michele Yaiser [6]: This paper focused on concepts of and inheritance contribute major role for reusability. inheritance and its applications. Paper also covered Encapsulation is also known as data hiding. Abstraction, encapsulation and overloading. In object oriented terminology, objects are basic run time Bruce L-Horn [8]: This paper presented different entity. More elaborate form it is well organized data mechanism and approaches to compare inheritance. It also structure which associates with set of operations, and emphasis on method combination method. operations recognized as behavior which is visible within Shivam [7]: This paper presented concept of inheritance object. Wrapping of data and function in single unit is and types of inheritance which provides the concept of known as class [1]. This paper is based on important use reusability of existing code. Paper focus on how inheritance and issues of virtual base class compile time plays major role and it is central concept in C++. polymorphism and run-time polymorphism using virtual As per above papers we conclude that work done on the function. Compile time polymorphism or early binding is a inheritance features to maintain more flexible mechanism process of function label which shows entry point of the for reusing code and encourages modular design and function at the time of compilation. This can be done using software reuse. method overloading. Function can be overloaded in two III Virtual Base Classes situations. First one when data types changed for It is also known as virtual inheritance. It is C++ arguments and second one number of parameters is techniques that ensure only one copy of base class changed [2]. members are inherited by grandchild derived class. In Run-time polymorphism can be done using virtual hybrid and specifically pure hybrid inheritance possibility function. It can be empty block or pure of generation of multiple paths [5]. C++ resolves it as a base defined in abstract class. Run-time polymorphisms can be class intended to be common throughout the hierarchy performed in inheritance only whereas compile time which is denoted as virtual using virtual keyword. It is used polymorphism can be done in same class. Virtual base to prevent from multiple instances of a given class which is class is implemented for avoiding duplication of access appearing in an inheritance hierarchy when using multiple multiple paths due to combination of different inheritance inheritances.

Author(s) agree that this article remain permanently open access under the terms of the Creative Commons Attribution License 4.0 International License Page 68 Ashok et.al/Virtual Base Class, Overloading and Overriding Design Pattern in Object Oriented Programming With C++

Figure Figure 1 demonstration about dreaded diamond } which refers to class structure in which a particular class void putmarks() appears more than once in a class inheritance hierarchy. { Such situation is recognized as ambiguity in C++. In said cout<<"\tMarks Obtained\n"; situation compiler get confusion because of multiple path cout<<"\n\tCPP:"<>score; } void putscore() { cout<<"\n\tSports Score is:"<

69 Ashok et.al/Virtual Base Class, Overloading and Overriding Design Pattern in Object Oriented Programming With C++ operator overloading it leads to wrong result. Object oriented language like Java does not allow operator Code 2: Sample Code for Late Binding using Virtual overloading because operator overloading provides Function multiple meaning for same operator which can make V Overriding learning curve for developer as well as developing applications and thing becomes more confusing and When you create an object of derived class and call the messing. member function which is exists in base and derived Early Binding: In early binding, an object is assigned to a classes, such circumstances member function of derived variable at the time of declaration of a specific object type. get invoked and base class member function is ignored. Early binding objects are strong type objects. In this type This feature of C++ is recognized as function overriding. of binding functions and properties of respective classes Function overriding can be resolved either compile time which are detected and checked during compile time and or run time. Following segment of code shows perform other optimization before an application executes demonstration of function overriding [5]. [2]. The biggest advantage of using early binding is better class base performance and ease of development. { ------Late Binding: In this type functions, variables and public: properties are detected and checked only at the run time. void getdata() It means that compiler does not know what types of object { ------contain until run time. Advantage of run time binding is } that the objects of this type can hold references to any }; object. It allows software systems to be more easily class derived : public base extended during both development and maintenance. { This Function will not be called Following code demonstration to how run time polymorphism can achieved in C++. ------#include public: #include void getdata() class base { ------{ } public: }; Function virtual void show() void main() call { { cout<<"\n Base class show:"; derived o1; } o1.getdata(); void display() } { cout<<"\n Base class display:" ; } Code 3: Sample Code for Overriding }; VI Issues of OOPs class drived:public base Once you understand concept of OOPs it is helpful to { develop any kind of applications. Although it have certain public: issues as far as design pattern is concern. Following issues void display() found in OOPs. { - A characteristic of OOPs is that it support concept cout<<"\n Drive class display:"; known as code centrality and it is connected with } inheritance. Many experts point out that code centrality void show() makes the code more expensive in terms of { cout<<"\n Drive class show:"; } maintenance. }; - create language and implementation complexity, especially in case of pure void main() hybrid inheritance i.e. combination of multiple and { clrscr(); hierarchical inheritance. Another issue of multiple base obj1; inheritances is it generates more cost for dynamic base *p; //Base class pointer implementation. cout<<"\n\t P points to base:\n" ; - When we use inheritance concepts and a requirement p=&obj1; is static perspective, it produces great result. But over p->display(); period of time requirement changed and thing that are p->show(); // Late Binding Ocuurs common from original perspective may be not common cout<<"\n\n\t P points to drive:\n"; when viewed by a new perspective. In such drive obj2; circumstances we need to rewrite . p=&obj2; - Dynamic binding have certain issues. It causes program p->display(); to be less reliable, because of lack of error-detection p->show();//Late Binding Ocuurs capability compare to early binding. Another big issue getche(); of dynamic binding is that it allows any variables to be base* b; assigned a value to any type, so it leads to produce derived d; //Derived class object wrong result. b = &d; VII Conclusion b->show(); }

70 Ashok et.al/Virtual Base Class, Overloading and Overriding Design Pattern in Object Oriented Programming With C++

In this paper I discussed how inheritance, overloading and [4] Shivam(2013), “A Study on Inheritance Using Object overriding play important role for code reusability and Oriented Programming with C++”, “International Journal developed modern design of software. The early binding of Advance Research in Computer Science and just mean that the target method is found at compile time Management Studies”, ISSN 2321-7782, Vol-1, Issue-2,July while in late binding the target method is looked up at run 2013, pp 10-21 time. Example of late binding is script language and [5] Herbert Schidlt, “The Complete Reference C++”, Third compiled languages are early binding. In conclusion Edition, McGraw-Hill Publication function overloading is modification techniques and [6] Michelle Yaiser (2012) “Object-oriented programming function overriding is a replacement technique. concepts: Inheritance”, Feb 2012 ACKNOWLEDGMENT [7] Shivam(2013), “A Study on Inheritance Using Object I wish to acknowledge and thanks very much to my entire Oriented Programming with C++”, “ CASPS family which helps me to work hard towards International Journal of Advance Research in Computer producing this work. Science and Management Studies”, REFERENCES Volume 1, Issue 2, July 2013, ISSN: 2321-7782, pp 10-21 [1] E Blagurusamy, “Object Oriented Programming With [8] Bruce L. Horn (1998), “An introduction to object C++”, Second Edition , TMH oriented programming, inheritance and method [2] Suvarnalata Hiremath et. al(2016), “Review Paper on combination”, Carnegie Mellon University Inheritance and issues in Object Oriented Languages”, Web Reference “International Journal of Advancement in Engineering [1] https://en.wikipedia.org/wiki/Object- Technology, Management & Applied Sciences”, ISSN 2349- oriented_programming 3224, Volume3, Issue 2, May 2016, pp 63-66. [2] [3] Iqbaldeep Kaur st. al(2016), “Research Paper on Object https://www.codeproject.com/Articles/22769/Introducti Oriented Software Engineering”, ” International Journal of on-to-Object-Oriented-Programming-Concept Computer Science and Technology”, ISSN : 0976-8491, Vol 7 , Issue 4, Oct-Dec-2016, pp 36-38

71