This makes it easier to update or replace objects, as long as their interfaces are compatible, without affecting other objects and code. An operation may exhibit different behavior in different instances. The behavior depends upon the types of data used in the operation. Objectives of the Topic i Describe the principles of the OOP principles ii Describe the application of the principles.
As its name suggests it was used to create simulations. He had a vision of a personal computer that would provide graphics-oriented applications and he felt that a language like SIMULA would provide a good way for non- specialists to create these applications. He sold his vision to Xerox Parc and in the early s, a team headed by Alan Kay at Xerox Parc created the first personal computer called the Dynabook.
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. Along with inheritance, encapsulation and abstraction form the three central principles of object-oriented programming. Inheritance is a mechanism that allows one class to gain the properties of another class, in the same way, that a child inherits some attributes from each of their parents.
Inheritance allows programmers to create a new class that reuses the data members and methods of an existing class. Abstraction occurs when a programmer hides any irrelevant data about an object or an instantiated class to reduce complexity and help users interact with a program more efficiently.
The term abstraction vs encapsulation can be used to describe the process of hiding some of the information contained in an object or class, but it may also refer to the object itself. An abstraction is any named entity that contains a selection of data and behaviors specific to a particular usage of the originating entity. Stated differently, an abstraction relates to how an object and its behaviors are presented to the user and encapsulation is a methodology that helps create that experience.
Think about the interface of your mobile phone. Whether you use an Android operating system or iOS, you don't interact directly with the code that allows your phone to connect to the internet, send a text message or play a video game. Instead, you interact with the code through a user interface that is designed to streamline your experience and make it easy to access the functions and methods you need to complete a task.
In this case, the interface is abstracted away from the actual implementation of the code. Containers are a relatively new type of software that can be used to virtually package a piece of code along with all of its libraries and other dependencies that it needs to execute. Containers create an encapsulated virtual environment where an application can be launched using the minimum amount of storage space and computing power.
A group of containers can share access to a single operating system and draw their computing resources from a single piece of hardware.
Containerization has emerged as an alternative to virtual machines because of its highly efficient usage of computing resources. Virtualization allowed multiple operating systems and applications to run at the same time while sharing the resources of a single computer. Containers improved on this model by sharing a host operating system and installing the container runtime engine onto the host machine's operating system. A computer running four virtual machines expends additional resources for each instance of the operating system that it runs, while a computer with an installed containerization engine could run the same number of applications on a single operating system.
As a result, multiple containers can operate using the same computing capacity as a single virtual machine. This helps to write redundant free code and also reduces code length. Super class is that class which is inherited by other class. In other words, super class is a class from which sub class inherits the properties and behaviors.
It is also called base class or parent class. Sub class is that class which inherits other class. In other words, sub class is a class which inherits the properties and behaviors of super class. It is also called child class or derived class. When a class inherits properties and behavior of only one class then this type of inheritance is called single inheritance. When a class inherits other class and then that inherited class further inherited by other class, this type of inheritance is called multilevel inheritance.
In multilevel inheritance, sub class contains the properties of the base class as well as properties of base class of its own base class. When a class inherits the properties and behaviors of more than one class then this type of inheritance is called multiple inheritance. When more than one class inherits the properties or behavior of only one class then this type of inheritance is called hierarchical inheritance. It is process of performing a single task in different ways. In polymorphism, one method have multiple forms based on the type of parameters, order of parameters, and number of parameters.
The polymorphism that takes place during compile time is called compile time polymorphism. It is also called static polymorphism or early binding. In this type of polymorphism, a class contain multiple methods having same name but different signatures. The polymorphism that takes place during run time is called compile time polymorphism. It is also called dynamic polymorphism or late binding.
Runtime polymorphism refers to the process when a call to an overridden process is resolved at the run time. In this type of polymorphism, the sub class and base class both contain methods having same name which can have different functionalities.
When a class contains multiple methods having same name but different signature, this is called method overloading. In method overloading, multiple methods of same names performs different tasks within the same class. When base class contain a method and sub class also contain same name method of its parent class, this is called method overriding. Method overriding is used to provide the specific implementation of a method which is already provided by its superclass.
Operator overloading is a mechanism in which the operator is overloaded to provide the special meaning to the user-defined data type. Static functions are those functions that can be called without creating an object of the class.
That means, Static methods do not use any instance variables of any object of the class they are defined in. Virtual function is a function or method used to override the behavior of the function in an inherited class with the same signature to achieve the polymorphism. Virtual function defined in the base class and overridden in the inherited class. The Virtual function cannot be private, as the private functions cannot be overridden.
It is used to achieve runtime polymorphism. A pure virtual function is that function which have no definition.
A pure virtual function have not definitions but we must override that function in the derived class, otherwise the derived class will also become abstract class. Constructor is a special type of member function which is used to initialize an object. It is called when an object of the class is created. At the time of calling constructor, memory for the object is allocated in the memory.
The constructor method having the argument list or parameter list is called as parameterized constructor as it initializes the fields with the values of the parameters. A copy constructor is that constructor which use existing object to create a new object. It copy variables from another object of the same class to create a new object. A static constructor is automatically called when the first instance is generated, or any static member is referenced.
The static constructor is explicitly declared by using a static keyword. However, the static constructor is not supported in Java. Java enables us to declare a constructor as private. We can declare a constructor private by using the private access specifier.
Note that if a constructor is declared private, we cannot create an object of the class. Instead, we can use this private constructor in Singleton Design Pattern. Destructor is a type of member function which is used to destroy an object. It is called automatically when the object goes out of scope or is explicitly destroyed by a call to delete.
It destroy the objects when they are no longer in use. The constructor method of the class may or may not have the argument list, and it has no return type specified and we also know that method overloading depends only on the argument list and not on the return type.
Thus, we can say that the constructor method can be overloaded.
0コメント