Intro to OOP (part 2)

Posted by Tyler Jones on May 2, 2021

​ Welcome to the second part of my Object Oriented Programming (OOP) blog series, if you haven’t read the first one check it out here. As we delve a bit further into OOP fundamentals and concepts ill include further readings and resources at the bottom to cover specificities.

​ Inheritance allows new objects and classes to inherit the existing attributes and methods of another object or class. There are two main kinds of inheritance, multiple and single, in which object can inherit one or more classes. Multiple Inheritance is, just as it sounds, when one child class inherits from more than one parent class. Not all languages support this however because multiple inheritance can be overly complicated and difficult to manage. Single Inheritance forces you to focus on abstraction. Think of single inheritance as a tree and at its base it should be the most abstract and dynamic. As the tree branches out it becomes more specific.

​ Class-based inheritance in which the structure of objects are defined in classes. New objects created from a class become an instance of it and inherit the attributes and methods defined within the class. Prototype-based inheritance in which objects are based on copies or clones of existing objects. Structured objects with attributes and methods can share them to its prototype. For example if objectA has a name, age, and height then an instance of objectA will inherit the attributes along with their values and can change or add its own. If objectB has hairColor, eyeColor, and height it will have the same name and age as objectA but a different height.

​ Polymorphism is the ability to have many forms of the same interface and is commonly known for two different types. The first type, dynamic polymorphism, is allowing access to methods that come from the same interface and implementing them in different ways depending on the object. The second type is called static polymorphism which uses a method overloading feature. Method overloading also allows access to methods from the same interface but, uses a different set or amount of inputs.

This concludes the two part intro series, I may continue the series in a more in depth way. Along with part one I’ve coved the main concepts and ideology of OOP be sure to look at the resources below and fall down the rabbit hole as I have.

Resources:

SO - Polymorphism

Medium - Polymorphism

Wiki - Prototype-based

Wiki - Class-based

Wiki - OOP

Wiki - OOA

SO - OOP