7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.2 Abstraction

Depending who you talk to, abstraction can sometimes be left out of the list of principles of OOP. Whether it should be included or not, we are going to discuss it briefly in this lesson just to make sure you are familiar with the concept.

3.2 Abstraction

The first principle of object-oriented programming that I'm going to discuss within this course is actually something you've already really learned, just not within the context of object-oriented programming. So the first thing I'd like to talk to you about very briefly is the concept of abstraction. Now, abstraction is really just being able to model some real world objects or things or functionality into our application so that we can use that particular functionality within our applications, similarly to how we would actually use that thing out in the real world. So the way that we've learned to do this so far is through the use of classes, or structures, or even enumerations should use, should you choose to use them that way. So an example of this might be if we have an application that has to do something with a car, maybe tracking mileage, or doing something along those lines, we could create a, an abstract data type that could model a car in the real world. So we could do that by creating a class, and we could call it Car. And we would start to define a series of properties and methods that could describe that particular object or, in this case, a car. So I could create a property named numberOfWheels. And we'll say that, that's an integer and we'll say that, by default, that's gonna be 4. And then we could create a numberOfDoors. And that would be an integer as well, and we can start that off as being 4. And then we can create methods on car that would describe some actions that the car could actually take. So we could create a function here that would say maybe, Drive, with no inputs and no outputs, and this obviously did some sort of functionality. And maybe we would have something that would maybe start the car or the things of that nature. So we could continue to model this Car class after the real world object or real world concepts that are associated with a car. And then, throughout our application, we could use this car very similarly to how we would use a car in the real world. With the exception of, obviously, getting in it and driving it. But we would be able to represent it with this abstract data type known as a Car class. So that's the basic fundamental idea behind abstractions. So a lot of times, you don't hear people talk about that one, simply because it's kind of a given. If you are using object-oriented programming, you're going to have the concept of a class in that language, and that's in and of itself is pretty much abstraction. So now that we have the basic idea about what abstraction is, let's go ahead and dig into the three other more popular ideas around object-oriented programming.

Back to the top