First Test Notes
Advantages of Object-Oriented Programming:
-Code is organized into classes, making it easier to manage, modify, and understand
Example: A class
Carcan 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
SportsCarclass can inherit from a baseCarclass and add specific features liketurboBoost()
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
BookandMember, 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 (
book1andmember1) of the classesBookandMember, 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)
Doginherits thenameattribute and thespeakmethod fromAnimal
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_numberand__balanceare 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
Studentis associated with aCourse. The relationship is unidirectional because onlyStudentknows aboutCourse, 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
Libraryclass contains a list ofBookobjects, but theBookobjects can exist independently of theLibrary
Composition:
-Composition is a design principle in OOP that represents a strong "has-a" relationship between two classes
The
Carclass contains anEngineobject. TheEnginecannot exist independently of theCar. If theCarobject is destroyed, theEngineobject is also destroyed, illustrating a composition relationship