OOP principles

From Computer Science Wiki
Revision as of 14:47, 3 January 2023 by Bmackenty (talk | contribs) (Created page with "=== Students must be able to explain how the real world can be represented using objects, how different objects can be used together to represent a more complex model, and how...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Students must be able to explain how the real world can be represented using objects, how different objects can be used together to represent a more complex model, and how objects work together in a hierarchy of classes.[edit]

In object-oriented programming, objects are used to represent real-world entities or concepts. For example, you could create a Car object to represent a car, with properties like make, model, and year, and methods like start and drive.

Objects can also be used to represent more complex concepts by combining simpler objects together. For example, you could create a Person object with a Car object as a property, to represent the relationship between a person and the car they own.

Objects can also be organized into a hierarchy of classes, with more general classes at the top and more specific classes below. For example, you could have a class hierarchy where the top-level class is Vehicle, with subclasses like Car, Truck, and Bicycle, each with their own specific properties and methods. This allows you to take advantage of inheritance, where subclasses can inherit properties and methods from their parent class, and you can use polymorphism to write code that can work with multiple different types of objects in a uniform way.


Students must be able to explain Abstraction, Encapsulation, Inheritance, and Polymorphism in the context of object-oriented programming.[edit]

Abstraction, encapsulation, inheritance, and polymorphism are four fundamental concepts in object-oriented programming.

Abstraction refers to the process of representing the essential features of an object without including the implementation details. This allows you to focus on what an object does, rather than how it does it. In object-oriented programming, abstraction is often achieved through the use of interfaces or abstract classes, which define a set of methods that an object must implement, but do not provide an implementation for those methods.

Encapsulation refers to the bundling of data and methods that operate on that data within a single unit, or object. This allows you to hide the implementation details of an object from other parts of the program, making it easier to change the implementation without affecting the rest of the program. Encapsulation also allows you to control how other parts of the program can access and modify the data stored in an object.

Inheritance refers to the ability of a class to inherit properties and methods from a parent class. This allows you to create a new class that is a modified version of an existing class, without having to rewrite all of the code in the new class. Inheritance is a powerful tool that allows you to reuse code and create a hierarchy of classes that represent a relationships between different concepts.

Polymorphism refers to the ability of different objects to respond to the same method call in different ways. This allows you to write code that can work with multiple different types of objects in a uniform way, without having to know exactly what type of object you are working with. Polymorphism can be achieved through inheritance, by defining methods in a base class and then overriding those methods in derived classes to provide different behavior.


Students must be able to identify the most important data to build a model, and describe relationships between objects.[edit]

Identifying the most important data to build a model is a crucial step in object-oriented programming. It involves identifying the key concepts or entities that you need to represent in your model, and determining the attributes (properties) and behavior (methods) that each object should have.

For example, if you are building a model of a car, you might identify the following objects:

  1. Car
  2. Engine
  3. Wheel

Each of these objects would have attributes that describe its properties, such as:

  1. Car: make, model, year, color
  2. Engine: horsepower, fuel type
  3. Wheel: diameter, tread type

And each object would have methods that define its behavior, such as:

  1. Car: start, drive, stop
  2. Engine: start, stop
  3. Wheel: rotate

It's also important to identify the relationships between objects when building a model. For example, in the car model, there is a relationship between a Car object and its Engine object, as well as between a Car object and its Wheel objects. These relationships can be represented using object properties. For example, the Car object could have an engine property that refers to an Engine object, and an wheels property that refers to a list of Wheel objects.

Understanding these relationships is important because it allows you to model complex concepts in a way that reflects the real-world relationships between those concepts, and it allows you to use the methods and properties of related objects in a more intuitive way.


Students must be able to discuss the advantages and need for encapsulation, and understand how encapsulation increases security.[edit]