You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the key concepts of object-oriented programming (OOP) and design: classes, objects, inheritance, polymorphism, encapsulation and abstraction. The OCR H446 specification requires you to understand these concepts and apply them to design problems.
| Concept | Definition |
|---|---|
| Class | A blueprint or template that defines the attributes (data) and methods (behaviours) that objects of that type will have |
| Object | A specific instance of a class, with its own values for the class's attributes |
Analogy: A class is like a cookie cutter (the template); objects are the individual cookies (each with its own specific details).
Class: Dog
Attributes: name, breed, age
Methods: bark(), fetch(), sit()
Object 1: Dog("Rex", "Labrador", 5)
Object 2: Dog("Bella", "Poodle", 3)
Each object has its own values for name, breed and age, but they share the same methods defined in the class.
Encapsulation means bundling the data (attributes) and the methods that operate on that data together inside a class, and restricting direct access to the internal state from outside the class.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.