The 3 Pillars of Object-Oriented Programming (OOP) Brought Down to Earth
By Tech Elevator Instructor Ben Langhinrichs
Tech Elevator offers both Java and C# languages as part of an object-oriented, full-stack web development curriculum. While we use these two languages based on overall industry demand and specific feedback from our hiring partners, most programming languages today are object-oriented—so these underlying principles and skills apply to almost all software development jobs.
But with any highly intensive course of study, the pragmatic needs of building code, designing databases, and using the plethora of programming tools can crowd out any memory of the big concepts. The following overview originated during a review session I gave for both Java and C# students at Tech Elevator to help remind them of the core pillars of object-oriented programming. Keep reading to learn more about object-oriented programming and its three major pillars.
Object-Oriented Programming Explained
Object-oriented programming: Refers to the practice of defining classes and objects to organize code, and is used in most programming languages today. There are three major pillars on which object-oriented programming relies: encapsulation, inheritance, and polymorphism.
Phew! Even writing that makes my head spin. Students of programming hear these terms, and learn lots of ways to use them in their programming, but sometimes struggle to understand what is what. Hopefully, this slide can bring the three pillars down to earth and make them easier to remember.
If you are not familiar with the three pillars of OOP (object-oriented programming), let me explain a bit more what the terms mean, and what I mean by the slide.
- Encapsulation: This is the idea of wrapping everything up about a particular thing, whether a Checking Account or Armadillo, into a defined object with features and behaviors. Once we do, we can ask the object itself to do what it is supposed to do, whether that is Deposit Money or Defend Yourself. But nobody outside the object needs to worry about how it does its jobs. We just tell it to do it and go about our day. If everybody, and by this I mean every object, simply minds its own business and stays out of the business of other objects, all is good with the world.
- Inheritance: This is the idea that we don’t have to define absolutely everything about an object over and over again if it shares features and behaviors with other objects. We can define a class for Accounts and then let our Checking Account or Savings Account inherit all the stuff in common. Likewise, we can define a class for Animals, and let our Armadillo inherit features like Number Of Legs and Weight as well as behaviors such as Breathe and Sleep. We call these overarching classes parent classes, and the ones that inherit from them, child classes. We can then inherit from the child classes and so on. But our Checking Account is more specialized than our Accounts because we can Write A Check, which we can’t do with a Savings Account. Our Armadillo can Roll Into A Ball, but other animals such as a Giraffe don’t have that behavior. Since we go from more general to more specialized, I like to say that a child is like its parents, but much more special.
- Polymorphism: This fancy name just means that we can treat the same object as different things depending on how we need it at different times, and we can treat groups of different objects that share an ancestor or trait as if they were that ancestor or trait. So, we could have a set of different Checking, Savings, and Credit Accounts and ask each to Get Balance so we can figure out how much we have to spend on vacation this year. Or we could ask a queue of animals to Move Quickly, and not care how the Porpoise or Eagle or Armadillo would handle that shared behavior. I like to think that we are different things to different people, so even if not every Dungeon Master has a spouse to think him or her a nuisance, we can ask any of them to organize a game for Saturday night.
Interested in learning more about coding? Check out other free coding resources or take our Aptitude Test to see if you could be a fit for Tech Elevator’s coding bootcamp.
Learn how you can train the next generation of software developers by becoming a Tech Elevator instructor.
Ben has been developing software in a variety of languages and environments for many years. He has focused in recent years on high performance middleware services using C++ and Java, and data transformation code used to drive large scale web applications. Ben enjoys teaching and inspiring others which he gets to do every day as an Instructor at Tech Elevator Cleveland.