Object Orientated Programming Abstraction Inheritance Polymorphism encapsulation
The 4 pillars of Object Oriented Programming INHERITANCE ENCAPSULATION POLYMORPHISM ABSTRACTION
In a nutshell, inheritance is a process of creating new class from the existing one. The new class may have some additional properties and functionality. INHERITANCE
Encapsulation is the process of putting data and the operations (functions) that can be performed on that data into a single container called class. Now, any programmer can use this class without knowing how it is implemented. Due to encapsulation, data is insulated, thus not directly accessible from the outside world. This is known as Data Hiding. Remember, Encapsulation is not data hiding, but, Encapsulation leads to data hiding. ENCAPSULATION
Note on encapsulation – a helpful illustration A tiger can walk, smell, eat, hunt, kill and eat … The tiger can do all of these functions without ever knowing or seeing how it does them.
Poly means many and Morphs means forms Poly means many and Morphs means forms. Polymorphism refers to the ability to take multiple forms and it allows us to invoke derived class methods through a base class reference during run-time.. POLYMORPHISM
Abstraction is a process of exposing essential features of an entity by hiding the other irrelevant details. Abstraction mainly reduces complexity and increases efficiency. An entity can have multiple abstractions. ABSTRACTION
Note on Abstraction Source: https://www.google.co.uk/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0CAcQjRw&url=http%3A%2F%2Fwww.slideshare.net%2Fdmccreary%2Fsemantic-integrationpatterns&ei=wFpOVYTcJszy7AaJuYHABg&bvm=bv.92885102,d.ZGU&psig=AFQjCNHAdexlzOKpnKBo0YUj9djJvj374g&ust=1431284782665773
Object Oriented Programming This makes use of the idea of CLASSES and OBJECTS A Class is created (as a sort of ultimate BLUEPRINT or TEMPLATE) of an object. All Objects are then INSTANCES (or instantiations) of that CLASS.
PLATO Plato was born in Athens, Greece in the year 428 BCE and was tutored by Socrates (often credited as the father of Western philosophy). However, it is Plato, not Socrates, who is arguably the best known of the ancient Greek philosophers (if not of all philosophers), due in large to his profound influence on modern philosophy through his legacy of prolific writings; 35 dialogues and 13 letters.
Theory of Forms Beautiful?
What is Beauty?
Can the thing we call “beauty” be personified? What is Beauty?
Can the thing we call “beauty” be personified? What is Beauty?
The “Form” of True Beauty A flower is beautiful and a picture can also be said to be beautiful, but neither are beauty itself. Plato argues that the form of true beauty exists independently of the objects that have it, as such we may have a notion of perfect beauty, but can never actually experience it first hand.
Beauty is a quality INHERITED from the true form BEAUTY (that exists … Beauty is a quality INHERITED from the true form BEAUTY (that exists ….somewhere!) In Plato’s parlance, a flower is said to partake of the form of beauty. It’s beautiful, but we never see true beauty. The flower is said to be a particular that inherits its qualities from the forms, one of which is beauty. The form of true beauty is constant and unchanging, whereas a flower may possess beauty for a while, but ultimately looses it when it withers and dies. Being abstract, forms exist independently of the particulars or real world objects that inherit their qualities.
Plato’s ideas are tat Every OBJECT, thing, thought or IDEA in this world is merely an “INSTANCE” or a MANIFESTATION of a TRUE AND ABSOLUTE TEMPLATE (or Class) of that object that exists in TRUE REALITY
Take Chairs…. A Chair (or a Chair Class) is like a TEMPLATE or an ABSTRACT (idea) of what a CHAIR is. The Chair class tells us WHAT A CHAIR COMPRISES OF, WHAT IT CAN DO, WHAT IT SHOULD LIKE, etc. A Chair Has legs Can be sat on Has a Colour Has a Shape
If a Carpenter made a Chair now …. The Chair INHERITS properties and methods from the original IDEA of a Chair. In programming we could call this a CLASS
Take Visual Basic and Buttons When you create a Button on a form you are: 1. Creating an INSTANCE of the BUTTON CLASS (The button class already exists and you cannot change it) The Button class defines what a Button is – what properties and events and methods it has. Every button you create can be clicked….will have a shape etc.
Everything in the toolbox has already been created as a Class.
When you make a button – you make an instance of the button class.
Pre-defined Properties of the Button Pre-defined Properties of the Button! (these are INHERITED from the Button Class)
C = Procedural Language What could go wrong here?
The main idea of OOP Is: To gather data AND Methods (functions) that act upon that data into ONE entity – called a CLASS. When you have a class it means 1 DATA HIDING 2 CODE RE-USE and 3 PROGRAM MAINTENANCE much easier!
Classes can be thought of as “Black Boxes” Other programmers don’t know what the class contains but can manipulate it using its METHODS
Languages in the olden days Treated data and Programming instructions as separate things
Derived Class? A Class that has all the properties and methods (or attributes and operations) of its super class but may also have attributes and operations of its own!
The 4 pillars of Object Oriented Programming INHERITANCE ENCAPSULATION POLYMORPHISM ABSTRACTION
Inheritance? A Derived Class INHERITS all the attributes and operations from its super class.
Encapsulation? Data Hiding Data can only be accessed using operations or methods defined for the class Maintains data integrity
Polymorphism Data Hiding Data can only be accessed using operations or methods defined for the class Maintains data integrity
What are the advantages of OOP?
Disadvantages of OOP?
From http://www. richardfarrar Throughout his metaphysical discussions, Plato refers to forms as abstract representations that are templates or patterns for real world objects or characteristics of objects. By way of example, to explain the concept of a form, Plato discusses the concept of beauty. A flower is beautiful and a picture can also be said to be beautiful, but neither are beauty itself. Plato argues that the form of true beauty exists independently of the objects that have it, as such we may have a notion of perfect beauty, but can never actually experience it first hand. In Plato’s parlance, a flower is said to partake of the form of beauty. It’s beautiful, but we never see true beauty. The flower is said to be a particular that inherits its qualities from the forms, one of which is beauty. The form of true beauty is constant and unchanging, whereas a flower may possess beauty for a while, but ultimately looses it when it withers and dies. Being abstract, forms exist independently of the particulars or real world objects that inherit their qualities. Heavy stuff at the best of times, let alone for over two millennia ago.