DEV Community

WestonDease
WestonDease

Posted on

OOP Part 2

Last time we took a look at the four main principles behind OOP and what makes them useful. This time we will look at inheritance and polymorphism and how they work.

  1. Inheritance

With inheritance a developer can create large sets of data quickly and easily. When a class is created that expands and is built on another class that object will take on all properties and operations that the parent class has. Classes that have this relationship are called super classes with the case of a parent class and ???? with the case of child classes. For some programming languages like Java and C# these properties can be overwritten in implementation of child classes, however in other cases such as JavaScript this option is not available.

  1. Polymorphism

Polymorphism and inheritance are intrinsically linked together as they are both a natural result of embedded classes. To embed a class requires inheritance as the whole point of classes are to pre-establish attributes of a data set. As you go a layer deeper to embedded classes, these potential classes also gain the attributes in the same way any regular instance of the object would behave. Where this concept really takes off is in the concept of polymorphism.

For embedded classes we take an object and essentially make the parent class and turn treat it as another variable to be applied to the child class. While it's certainly more complex than "just another variable" as methods and groups of variables are added to the picture, it is a useful way to think about polymorphism in this way. When taking this approach the sheer possibilities of classes is reveals itself. Variable types are a bit of a tool belt for programmers and while you could argue that there is a hard limit on the types of data that can possibly represented by variables such as numerical data with int or float, symbolic representational data that has perhaps a cultural meaning like how strings represent words of whatever language is used or perhaps even encoded data with the case of letters in encrypted data, or simple true/false values such as booleans, The way groups of data are defined and manipulated with functions is perhaps the true "variable" we are looking for in the cases of high complexity solutions. Of course we should try to make our functions and objects pure, that is, have them perfectly implemented to be self-contained by relying only on data stored in the object and have functions only rely on data passed to as an argument. By designing in this way, programs can interact with each other in such a way to make unfathomably complex programs.

Conclusion

Ultimately, OOP is a (maybe i haven't used this word yet) complex concept but exists for us as flawed, simple humans. The uses for these principles are designed to help us understand what it is were actually doing when were stringing together long chains of 1's and 0's. This is the same concept that provides the power behind programming languages and compilers, operating systems, and even user interface whether that be digital or analog. Humans cant really understand the enormous number of boolean operations required to create what we have with computers. I start to loose myself in the complexity of an ALU graphed out with all of its logic gates and flags. But anyway I hope this guide gave understanding and context to just how gargantuan an undertaking computer systems are and their potentially infinite uses.

Top comments (0)