|Language:||English, Spanish, Dutch|
|Genre:||Academic & Education|
|ePub File Size:||18.86 MB|
|PDF File Size:||15.33 MB|
|Distribution:||Free* [*Sign up for free]|
Object Oriented Programming is a programming concept that works on the principle that objects are the most important part of your program. It allows users create the objects that they want and then create methods to handle those objects. Manipulating these objects to get results is the goal of Object Oriented Programming.
It is only an logical component and not the physical entity. Its properties data can be price or speed of these cars.
While the methods may be performed with these cars are driving, reverse, braking etc. An Object contains both the data and the function, which operates on the data. For example - chair, bike, marker, pen, table, car, etc.
It offers robust and natural mechanism for organizing and structure of any software. For example, in English, the verb run has a different meaning if you use it with a laptop, a foot race, and business.
Here, we understand the meaning of run based on the other words used along with it. The same also applied to Polymorphism. It is a technique of creating a new data type that is suited for a specific application. Encapsulation Closely associated with message passing and dynamic dispatch is the concept of encapsulation.
Encapsulation means that code outside of an object cannot directly access its internal data. This is usually done with a method call.
However, many experts in OO development encourage programmers to adhere to encapsulation principles by not calling properties directly , even in languages that allow it. There are many benefits to encapsulation. Primarily, it allows any details or side effects to be abstracted away from the point at which the property is called. For example, each time a particular value is read, you might want to check when it was last calculated, and re-calculate it if certain conditions are met.
Being able to add, remove, or change that logic in one place at any time, without affecting any of the other places in the code which make the call, is a benefit of encapsulation. Inheritance and Composition Inheritance and composition are two ways that various classes and their instantiated objects are related to each other. In this example, there might be a Person class which defines all the properties and methods of Persons in general name, birthday. Then a User class would extend the Person class, to add things like a username attribute or login and logout methods.
Like the inheritance hierarchy, the compositional hierarchy can easily be several layers deep. Much of the design work in object-oriented development has to do with mapping out these relationships of inheritance and composition.
The class diagram , which is a part of the Unified Modeling Language is an invaluable tool for visualizing these relationships. Polymorphism Polymorphism or, more specifically, subtype polymorphism is a concept that naturally comes out of inheritance. Each subclass might implement the method differently, but calling objects do not need to know which of several subtypes they are calling.
They can treat all different subtypes of objects as equivalent. Polymorphism is a big subject, and is not without controversy. Learn More About Object-oriented Programming For a deep understanding of object-oriented programming, a number of classic and contemporary books on the subject are invaluable, and can hardly be replaced by online tutorials.
Important Object-Oriented Languages Not all programming languages support object-oriented programming. Some languages are designed to do nothing but support OOP.
Others allow for a variety of approaches to programming. Still others appear to be object-oriented, but implement the concepts of object-orientation in non-standard, incomplete, or just plain unusual ways.
Below is a list of some of the more popular OO-capabable languages, with notes about their approach to Object Orientation, and some resources to help you get into OOP with that language. The internet is filled with essays that look at language X vs language Y — most of which just scratch the surface.
We suggest you check out this more general Programming Language Comparison. Check it out:. Here, createPerson name returns an object literal that can now be used as a normal object. You can pass parameters to easily tweak objects you want to reuse with different properties. Factory functions provide an element of re-usability while retaining a lot of the flexibility you get with object literals.
These functions are the most conventional way to create objects that use functionality from each other using prototypal inheritance. What is prototypal inheritance, you ask? Let me show you using constructor functions.
Take the Person object from the last two examples:. Here is where it gets interesting.
I know this can be super confusing. If you have any questions or would like clarity on how exactly prototypes work, please send me a message or comment and check out the docs at Mozilla. So why do I need to use constructor functions?
Well one concept of OOP is to write reusable and easily extendable code. What if I want to make an extended version of a Person? How about an Athlete? Here are the steps to implement prototypal inheritance with minimal verbosity:.