First Test Notes

Advantages of Object-Oriented Programming:

-Code is organized into classes, making it easier to manage, modify, and understand

  • Example: A class Car can encapsulate all properties (e.g., color, speed) and behaviors (e.g., start(), stop()) of a car, making the code reusable and maintainable

-OOP supports inheritance, allowing new classes to reuse and extend existing ones

  • Example: A SportsCar class can inherit from a base Car class and add specific features like turboBoost()

Disadvantages of Object-Oriented Programming:

-OOP concepts like inheritance, polymorphism, and abstraction can be challenging to grasp for beginners

  • Example: Understanding how abstract classes and interfaces work can confuse new programmers

-OOP programs can be slower than procedural ones due to additional layers like object instantiation and method calls

  • Example: A simple calculator program may run faster if written procedurally rather than in OOP


Differences between class and object diagrams:

Class:

-A class diagram represents the static structure of a system, showing the classes, their attributes, methods, and the relationships between them

  • Ex: A diagram shows the classes Book and Member, their attributes, and methods, along with a relationship indicating that members can borrow books

Object:

-An object diagram represents a snapshot of the system at a particular point in time, showing the instances (objects) of classes and their specific values

  • A diagram shows specific instances (book1 and member1) of the classes Book and Member, with actual values for their attributes


Inheritance:

-A mechanism in OOP where a child class (subclass) derives properties and behaviors (attributes and methods) from a parent class (superclass)

  • Dog inherits the name attribute and the speak method from Animal


Virtualization:

-Virtualization often refers to the concept of polymorphism, specifically the use of virtual functions or methods

  • The speak() method in the parent class is declared as virtual


Encapsulation:

-A principle of OOP that involves bundling data (attributes) and methods (functions) operating on the data into a single unit, i.e., a class

  • The attributes __account_number and __balance are private, meaning they cannot be accessed directly from outside the class


Association:

-A relationship between two or more objects where one object uses or interacts with another

  • Student is associated with a Course. The relationship is unidirectional because only Student knows about Course, but not vice versa


Aggregation:

-A special form of association in OOP that represents a "has-a" relationship between two classes, where the whole (container) object and the part (contained) object are loosely coupled

  • The Library class contains a list of Book objects, but the Book objects can exist independently of the Library


Composition:

-Composition is a design principle in OOP that represents a strong "has-a" relationship between two classes

  • The Car class contains an Engine object. The Engine cannot exist independently of the Car. If the Car object is destroyed, the Engine object is also destroyed, illustrating a composition relationship