Five Basic Concepts of Object-Oriented Design

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: GRASP Design Patterns in Object-Oriented Design

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
 Replay
Your next lesson will play in 10 seconds
  • 0:04 A World of Objects
  • 0:50 Classes and Objects
  • 1:23 Inheritance
  • 2:08 Encapsulation,…
  • 3:44 Polymorphism
  • 4:46 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Timeline
Autoplay
Autoplay
Speed Speed

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

There are five key pillars of object-oriented design. In this lesson, we will cover the five core concepts of objects/classes, inheritance, encapsulation, methods, and polymorphism.

A World of Objects

The concept of object-oriented design (OOD) may seem hard to grasp at first. But consider that everything in the world is an object. Within a forest, there are trees, shrubs, leaves, and animals. All of these objects are instances of their respective species. That is, each budding maple tree belongs to the class of the Maple tree.

Some of these objects are related and some of them inherit traits from other objects. A spruce tree inherits all the traits of a tree and all the traits of an evergreen tree. When completing an object-oriented design, there are five basic concepts to understand: classes/objects, encapsulation/data hiding, inheritance, polymorphism, and interfaces/methods.

Classes and Objects

A Maple (capital M) is a class. We capitalize it because it's the blueprint. When seeds drop and sprout, the growing maple tree is really an instance, or a type, of the Maple class. The growing maple tree is considered an object, that is, an instance of a class. To reiterate: a newly-growing maple tree is an instance of the Maple class

This is the only time we'll show code in this lesson, but here it reinforces the fundamentals of object-oriented design (objects are instances of classes).

Maple maple = new Maple();

Inheritance

Recall that a spruce tree will have features of all trees, plus features from evergreen trees. A Spruce class will inherit all of the features of the Tree class. Just like we inherit genes and traits from our parents, so too do classes in object-oriented design. In this case, the variables and methods in the Tree class are available to the Spruce class.

The graphic below is a good depiction both of class hierarchy and inheritance, although it is not comprehensive. In this case, the parent of everybody is the Tree class. As you move down the chart, each of the classes is a child class, or subclass, of the parent above it.


Class Hierarchy and Inheritance
Inheritance


Not only does Red Pine inherit from Pine, but from Evergreen, and the top parent Tree class.

Encapsulation, Interfaces, Methods

Encapsulation is a fancy word to describe the protection, or hiding, of data. The power of objected-oriented design is that you can protect certain data in certain classes from being used. Remember that the Spruce class inherited everything from the Evergreen class. But what if you don't want everything to be passed down to children? Although we're focusing on trees here, think about things like age and pay rate. These are items we would definitely want to keep close to the vest in a system. We would not want to allow other classes to get at these items.

Let's say the Deciduous class has a method, or process, for growth changes in the fall. We'll call it fallChanges(). Within it are all sorts of variables for modifications as the season approaches winter (rate of leaf fall, color change rate). We don't need to expose any of that to the Evergreen class. In fact, as you design an object-oriented program or system, it's best to start out by encapsulating data. That is, don't make everything public. It's best to start off with more restrictions since this prevents inappropriate access of items in classes.

An instance of a Maple class (a maple) will change colors in the fall. To do so it needs a method, or a function that performs an action. Part of the color change could be in the fallChanges() method mentioned earlier.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support