1/24
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
WHAT IS OBJECT – ORIENTED
PROGRAMMING (OOP)?
Object-oriented programming (OOP) is a software
development paradigm which encourages sculpting
desired entities with properties and methods in
named classes to create applications.
OOP relies on two major concepts: the CLASS and
the OBJECT - these foundational concepts applied in
code enable us to build applications.
WHAT IS OBJECT – ORIENTED
PROGRAMMING (OOP)?
Classes that have been instantiated in our code
become objects that can interact with one another
to perform the desired functions of the application.
Object oriented programming was created to guide
the creation of better software, by achieving easier
maintenance and reusability.
BENEFITS OF USING OOP: MODULARITY
OOP encourages the organization of software into discrete,
self-contained units (classes and objects).
This modularity makes it easier to manage, understand, and modify
code. Each class can be developed and tested independently, promoting
cleaner and more organized codebases.
BENEFITS OF USING OOP: REUSABILITY
OOP allows for the reuse of existing classes through inheritance and
polymorphism.
Code reuse reduces redundancy, saves development time, and ensures consistency across the application. For instance, a well-designed Vehicle class can be reused for creating Car, Bike, and Truck classes.
BENEFITS OF USING OOP: EXTENSIBILITY
OOP promotes the creation of systems that are easy to extend with new
features.
When new features or requirements arise, new classes can be added
with minimal impact on existing code. For example, adding a new
Airplane class to an existing hierarchy of Vehicle classes requires little to
no changes to existing classes.
BENEFITS OF USING OOP: MAINTAINABILITY
-The principles of encapsulation and abstraction help to create more
maintainable code.
-Encapsulation keeps data safe from outside interference and misuse,
making it easier to track and fix bugs. Abstraction hides complex details,
allowing developers to work with high-level interfaces, simplifying
maintenance and updates.
BENEFITS OF USING OOP: FLEXIBILITY AND SCALABILITY
-OOP systems can be easily adapted and scaled as new requirements
emerge.
-Polymorphism allows objects to be treated as instances of their parent
class, making it easier to introduce new subclasses without altering
existing code. This flexibility supports scalability and adaptability in
large and complex systems.
BENEFITS OF USING OOP: IMPROVED COLLABORATION
-OOP allows multiple developers to work on different parts of a project
simultaneously.
-By breaking down a project into classes and objects, teams can divide
the work more effectively, reducing conflicts and improving
collaboration. Each team member can focus on a specific class or set of
classes without affecting others.
BENEFITS OF USING OOP: REAL-WORLD MODELING
-OOP provides a clear structure for modeling real-world entities and
relationships.
-By using classes and objects to represent real-world entities (e.g.,
Person, Account, Transaction), OOP makes it easier to understand and
design complex systems that mimic real-world scenarios.
BENEFITS OF USING OOP: ENHANCED CODE READABILITY AND DOCUMENTATION
-OOP promotes writing self-explanatory and well-documented code.
-Well-defined classes and methods make the code more readable and
easier to understand. This clarity is beneficial for both current
development and future maintenance, as new developers can quickly
grasp the structure and functionality of the code.
OBJECT ORIENTED PROGRAMMING
VS.
PROCEDURAL PROGRAMMING
OBJECT ORIENTED PROGRAMMING
Bottom Up Approach
Divided into objects
Has Access Modifiers
Objects can move and communicate with other through member function
More secure
Supports overloading
PROCEDURAL PROGRAMMING
Top Down Approach
Divided into functions
Doesnt have access Modifiers
Data can move freely from function to function in the system
Less Secure
Does not support overloading
STRUCTURE OF OBJECT ORIENTED
PROGRAMMING:
Object-oriented programming contains
various structures, known as the building
blocks of OOP. These structures include:
CLASS
OBJECT
METHOD
ATTRIBUTE
CLASS
A class is a data type that provides a framework for creating objects. You can
define a class to create multiple objects without writing additional code.
OBJECT
In OOP, an object represents an instance, or creation, of a class. Objects define specific data, such as properties and behaviors, to implement code.
METHOD:
A method is a function that performs a task or action. For example, a method may return information about an object's data.
ATTRIBUTE:
This structure stores information about an object and defines its state. You can
define an attribute as part of the class.
4 CONCEPTS OF OOP
Encapsulation
Abstraction
Inheritance
Polymorphism
ENCAPSULATION:
Encapsulation means to enclose data by containing it within an object. In OOP, encapsulation forms a barrier around data to protect it from the rest of the code.
You can perform encapsulation by binding the data and its functions into a class.
This action conceals the private details of a class and only exposes the functionality essential for interfacing with it.
When a class doesn't allow direct access to its private data, it's well-encapsulated.
ENCAPSULATION Example
When creating a class to represent a person, you may define private data, such as the person's Social Security Number.
You can encapsulate this data as a private variable in the class, which means outside code can't access it.
If you write a method in the person class to perform a bank transaction, the function could access the data variable as necessary.
In this example, the person's private data is well-encapsulated within the class.
ABSTRACTION
Abstraction refers to using simplified classes, rather than complex implementation code, to access objects.
Often, it's easier to design a program when you can separate the interface of a class from its implementation.
In OOP, you can abstract the implementation details of a class and present a clean, easy-to-use interface through the class member functions.
Abstraction helps isolate the impact of changes made to the code so if an error occurs, the change only affects the implementation details of a class and not the outside code.
ABSTRACTION Example
Imagine a payment processing system with different payment methods like credit card, PayPal, and bank transfer.
Instead of dealing with the specifics of each payment method in the main system, you create an abstract class Payment with a method process_payment(amount).
This method is defined in such a way that any subclass must implement it, but the details of how the payment is processed are hidden.
INHERITANCE:
Most object-oriented programming languages support inheritance, enabling a new class to automatically acquire the properties and functions of its parent class.
Inheritance facilitates the organization of classes into hierarchies, where a class can have multiple parent or child classes.
When a class inherits from a parent class, it gains the properties and behaviors of the parent.
The child class can also alter or enhance the parent's functionality. This allows for code reuse without needing to redefine the child class's functions.
INHERITANCE Example
For instance, in the animal world, an insect may belong to an insect class.
In this class, all insects share similar properties, such as having six legs and an exoskeleton.
You can create subclasses for different varieties of insects, such as grasshoppers and ants.
These child classes inherit the properties of the insect class, meaning they share those same features.
POLYMORPHISM:
Polymorphism refers to creating objects with shared behaviors. In OOP, polymorphism allows for the uniform treatment of classes in a hierarchy.
When you write code for objects at the root of the hierarchy, any objects created by a child class within the hierarchy have the same functions.
Depending on the type of object, it may execute different behaviors.
POLYMORPHISM Example
If you have a class called animal with two child classes, cat and dog, you can create a class function to make a noise.
Using polymorphism, you can override this function inherited by the cat and dog child classes. Instead, you can make this function "meow" and "bark" for cat and dog, respectively.
Depending on the type of animal object that passes through the interface, it either makes a "meow" or a "bark" noise.