Современные информационные технологии / 2.Вычислительная техника и программирова­ние

 

Satmaganbetova Zh.Z., senior teacher

Kostanay State University named A.Baitursynov

Basic principles of Object- Oriented Programming

 

Programming has progressed a lot in a very short time. It started with a sequential programming in which the statements were following each other. Sequential programs are OK for basic tasks. However, solving a complex task with a sequential program is a challenging problem. With the increasing complexity of programs, programmers developed the modular programming technique after sequential Programming. A module is a sub-program (function in C++) that performs a specific task. Managing larger programs became easier with the help of modular programming. The focus of attention in modular programming is on modules (functions). It became possible for a group of programmers to work on a common project hence the software engineering concept emerged with modular programming.

Programmers have developed a new programming technique called Object- Oriented Programming (OOP). In this technique, computer programs are made up of objects. Programmers manage complexity by managing the individual object instead of the whole program. The focus of attention in OOP is on classes. You should think about how each object will be designed and how these objects interact. Especially visual programs and the Internet programs increased the complexity of programming. OOP is the best programming technique to manage such complex programs.

Object-oriented programming has roots that can be traced to the 1960s.

Object-oriented programming developed as the dominant programming methodology in the early and mid 1990s when programming languages supporting the techniques became widely available. These included Visual FoxPro 3.0, C++, and Delphi. Its dominance was further enhanced by the rising popularity of graphical user interfaces, which rely heavily upon object-oriented programming techniques. 

Object-oriented features have been added to many existing languages during that time, including Ada, BASIC, Fortran, Pascal, and others. Adding these features to languages that were not initially designed for them often led to problems with compatibility and maintainability of code.

More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as Python and Ruby. Probably the most commercially important recent object-oriented languages are Visual Basic.NET (VB.NET) and C#, both designed for Microsoft's .NET platform, and Java, developed by Sun Microsystems.

 Both frameworks show the benefit of using OOP by creating an abstraction from implementation in their own way. VB.NET and C# support cross-language inheritance, allowing classes defined in one language to subclass classes defined in the other language. Developers usually compile Java to bytecode, allowing Java to run on any operating system for which a Java virtual machine is available. VB.NET and C# make use of the Strategy pattern to accomplish cross-language inheritance, whereas Java makes use of the Adapter pattern.

We had variables and functions to manipulate variables in our programs so far. Object-Oriented Programming (OOP) encapsulates variables (data) and functions (methods) into packages called classes.

A class is the formal definition of an object, and an object is an instance of a class. A class is like a blueprint. Once a class has been defined, objects of that class can be declared from that class. A builder can build a house out of a blueprint. A programmer can instantiate (create) an object out of a class.

Object-oriented programming is built on three pillars: encapsulation, inheritance, and polymorphism.

OOP encloses data and the functions manipulate that data all within an object Holding the data and the related method in the same container is called encapsulation. Although classes contain both data and functions, not all of the class is accessible to other classes. Programmers let other classes access only the public methods of a class, and keep the rest of the class hidden in a private section.

New classes can be created from existing classes. This technique provides software re-usability to save time in program development. The new class inherits the data members and member functions of the existing class. The new class is called

“derived class” and the existing class is called “base class”. A derived class can add new data members and member functions or its own, or override its inherited methods. Thus, a derived class is more specific than its base class.

There are two main advantages of inheritance: code reuse and polymorphism. C++ and other OOP languages allow objects of different types to respond differently to the same function call. This feature is called polymorphism. Derived classes override the methods of base classes in polymorphism. For example, let

TRectangle and TTriangle classes be two different derived classes of the base class TShape, and let calculateArea be a method of the class TShape. The derived classes TRectangle and TTriangle override the calclateArea method to calculate their own

Encapsulation, inheritance and polymorphism are three fundamental principles of OOP (Object Oriented Programming). Encapsulation is the grouping of data and the code that manipulates it into a single object. Inheritance is a way to form new classes using pre-defined objects or classes where new ones simply take over old ones' implementations and characteristics. It is intended to help the re-use of existing code with little or no modification. Polymorphism allows objects to be represented in multiple forms. Even though classes are derived or inherited from the same parent class, each derived class will have its own behavior.

 In Object-Oriented Programming, software objects are often used to model the real-world objects that you find in everyday life.

References

1 Schach, Stephen. Object-Oriented and Classical Software Engineering, Seventh Edition. McGraw-Hill. 2006.  ISBN 0-073-19126-4.

 2 Фаронов В. Программирование баз данных в Delphi 7: учебный курс. –  С-Пб.: Питер, 2005. – 459 с.

 3 www.programmersforum.ru – форум программистов и администраторов.