Objected-oriented programming is a model to organize the code of a software developer aorund data and objects rather than functions and logic. An object is a data field that has unique attributes and behaviour.
A class in objected oriented programming is a canvas to create objects where you define the variables and the methods (functions) that the objects are going to do. A class determine how an object will behave and what the object will contain.
An object, in object-oriented programming (OOP), is an abstract data type created by a developer. It can include multiple properties and methods and may even contain other objects. In OOP, the structure of an object is defined by classes.
An instance is an object created from a class. To create an object from a class we use the "new" keyword. Class must be created prior to a instantiation.
The variables created in a class are call properties. A property is any data type (string, integer, array, object, etc). Before declaring a variable we should add the visibility keyword (public, private or protected).
Methods are functions inside classes. Their declaration are almost similiar to normal functions, except their special uses inside classes. We declare methods with visibility keywords.
A method is on an object or is static in class. A function is independent of any object.
Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
The destructor method will be called as soon as there are no other references to a particular object, or in any order during the shutdown sequence.
A class is a blueprint which you use to create objects. An object is an instance of a class - it's a concrete 'thing' that you made using a specific class. So, 'object' and 'instance' are the same thing, but the word 'instance' indicates the relationship of an object to its class.
In OOP encapsulation refers to a mechanism of restricting acces to some components of an object. For encapsulation we use visibility keywords (public, private and protected), we can use them for methods and variables.
In OOP, abstraction is a concept in which a class has methods without implementation. The idea is to have a template and let the child class that inherits the parent class implement the method.
Inheritance is one of the core concepts of object-oriented programming (OOP) languages. It is a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods.
Polymorphism is one of the core concepts of object-oriented programming (OOP) and describes situations in which something occurs in several different forms. In computer science, it describes the concept that you can access objects of different types through the same interface.
Function overloading or method overloading is a feature that allows creating several methods with the same name, which differ from each other in the type of input parameters. It is simply defined as the ability of one function to perform different tasks.
Overriding is an object-oriented programming feature that enables a child class to provide different implementation for a method that is already defined and/or implemented in its parent class or one of its parent classes. The overriden method in the child class should have the same name, signature, and parameters as the one in its parent class.
Overriding means, giving a different definition of an existing function with same parameters, and overloading means adding a different definition of an existing function with different parameters.
A static class is similar to a class that is both abstract and sealed. The difference between a static class and a non-static class is that a static class cannot be instantiated or inherited and that all of the members of the class are static in nature.
- Modularity for easier troubleshooting
- Reuse of code through inheritance
- Flexibility through polymorphism
- Effective problem solving
- Steep learning curve: The thought process involved in OO programming may not be natural for some people, and it will take the time to get used to it.
- The complexity of creating programs: it is very complex to create programs based on the interaction of objects. Some of the key programming techniques, such as inheritance and polymorphism, can be a big challenging to comprehend initially.