Let us see the following pictorial example to understand Objects. An object stores its information in attributes and discloses its behavior through methods. Let us now discuss in brief the different components of object oriented programming.
In object oriented programming, it binds the code and the data together and keeps them safe from outside interference.
The point where the software entities interact with each other either in a single computer or in a network is known as a public interface. This help in data security. Smalltalk was the object-oriented language developed for programming the Dynabook. It was a simulation and graphics-oriented programming language. Smalltalk exists to this day although it is not widely used commercially. The idea of object-oriented programming gained momentum in the s and in the early s Bjorn Stroustrup integrated object-oriented programming into the C language.
This project was going nowhere until the group re-oriented its focus and marketed Java as a language for programming Internet applications. The language has gained widespread popularity as the Internet has boomed, although its market penetration has been limited by its inefficiency. Discussing the OOP Principles Inheritance In object-oriented programming, Inheritance means the inheritance of another object's interface, and possibly its implementation as well.
Inheritance is accomplished by stating that a new class is a subclass of an existing class. The class that is inherited from is called the superclass.
The subclass always inherits the superclass's complete interface. It can extend the interface but it cannot delete any operations from the interface. The subclass also inherits the superclass's implementation, or in other words, the functions that implement the superclass's operations.
However, the subclass is free to define new functions for these operations. The subclass can selectively pick and choose which functions it overrides.
Any functions that are not overridden are inherited. There is a great deal of debate about how to use inheritance. In particular, the debate swirls about whether inheritance should be used when you want to inherit an interface or whether it should be used when you want to inherit implementation.
For example, suppose that you want to define a search object that stores key, value pairs and allows values to be looked up by providing their keys. Later we decide that we want a new object that allows us to traverse the key, value pairs in sorted order. The new object should support the above operations plus two additional operations, rewind that puts us back to the beginning, and next that returns the next key, value pair.
Since the new object supports all of the operations of the original search object, we can make the new object inherit the original object's interface. This is an example of interface inheritance. A radio alarm clock has all of the functions of a radio plus additional functions to handle the alarm clock. If we adopt the radio's interface for the radio alarm clock, then someone who knows how to operate a radio will also know how to operate the radio portion of the radio alarm clock.
Hence, rather than designing the radio alarm clock from scratch, we can extend or inherit the interface defined by the radio. Of course, we can also use the existing implementation for a radio and extend it to handle the alarm clock functions. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, wait, and cost, and function operate on these attributes. Eg:-When we change the gear of a car, we know the gears will be changed without knowing how they are functioning internally.
Abstraction focuses on the outside view of an object i. The attributes are sometimes called data members because they hold information. The functions that operate on these data are sometimes called methods or member function. Computer scientists use abstraction to understand and solve problems and communicate their solutions with the computer in some particular computer language.
This allows you to reduce a complex operation into a generalization that retains the base characteristics of the operation. For example, an abstract interface can be a well-known definition that supports data access operations using simple methods such as Get and Update.
Another form of abstraction could be metadata used to provide a mapping between two formats that hold structured data. Abstraction is something we do every day e. We abstract the properties of the object, and keep only what we need E. Any programming problem is analyzed based on objects and how they communicate amongst themselves.
The objects interact with each other by sending messages to one another when a program is executed. Each object contains code and data to manipulate the data. The entire set of code and data of an object can be made user-defined data type using the concept of the class. Any number of objects can be created after a class is created.
The collection of objects of similar types is termed as a class. For Example, apple, orange, and mango are the objects of the class Fruit.
Classes behave like built-in data types of a programming language but are user-defined data types. The wrapping up of the data and methods into the single unit is known as encapsulation. The data is accessible only to those methods, which are wrapped in the class, and not to the outside world. This insulation of data from the direct access of the program is called data hiding. Abstraction is the act of reducing programming complexity by representing essential features without including the background explanations or details.
Classes are the concept of abstraction and are defined as the list of abstract attributes such as size, weight, cost, and methods that operate on these attributes.
Classes wrap or encapsulate all the essential properties of the objects that are to be created. Inheritance is the process by which objects of one class acquire some properties of objects of another class. Inheritance supports the concept of hierarchical classification. For Example, a bird Robin is part of the class, not a mammal, which is again a part of the class Animal.
The principle behind this division is that each subclass shares common characteristics from the class from its parent class. In OOP, the idea of inheritance provides the concept of reusability. It means that we can add additional features to parent class without modification; this is possible by deriving a new class from the parent class.
The new class consists of the combined features from both the classes. In Java, the derived class is also known as the subclass. Polymorphism is an important OOP concept; it means the ability to take many forms. For Example, an operation exhibits different behavior in different situations.
The behavior depends on the type of data used in operation. For Example, in the operation of addition, the operation generates a sum for two numbers. If the operands are strings, then a third-string is produced by the operation by concatenation. The figure below demonstrates that a single function name can be used to handle the different numbers and different types of arguments. In polymorphism, objects having different internal structures can share the same external interface; it means that a class of operation may be accessed in the same manner even though actions with each operation may differ.
Inheritance extensively uses the concept of polymorphism.
0コメント