Explanation of 4 Oop Principles: Name Price Quantity Product - Java Fullname Address User - Java
Explanation of 4 Oop Principles: Name Price Quantity Product - Java Fullname Address User - Java
1. Inheritance:
● Concept:
Inheritance allows a class (child class) to inherit all attributes and methods from
another class (parent class). The child class can use, extend, or override the parent’s
methods and properties as needed.
● Implementation in the File:
○ Well-applied:
■ đọc phần phân tích code trong slide
● Why should we use inheritance in an online shopping app project?:
○ because it is highly relevant in designing an online shopping app. It enables
code reusability, hierarchy creation, and specialization.
○ Code Reusability: Avoid rewriting the same logic for multiple classes.
Common features (e.g., name, price, quantity in Product.java) are
defined once and reused by all child classes. Avoids duplication for attributes
like fullName, address in User.java
○ hierarchy creation:Inheritance hierarchy refers to the logical structure
organization of parent and child classes in a system, forming a hierarchy
where child classes inherit from parent classes. Creates clear parent-child
relationships, making the program easier to understand
○ Specialization: Each child class adds specific behaviors or attributes relevant
to its category (e.g., warranty for electronics, size for fashion). It focuses
on making child classes more relevant to their purpose while still maintaining
the foundational properties and behaviors of the parent class.
○ Easy Maintenance: Changes in the parent class automatically apply to all
child classes.
2. Encapsulation:
● Concept:
Encapsulation protects the internal data of an object by hiding it and exposing only
the necessary parts through public methods. It refers to the concept of hiding the
internal details of an object and only exposing a controlled interface to interact with
that object. Encapsulation ensures that an object's internal state (its data) is shielded
from external access and manipulation.
● Why should we use encapsulation in an online shopping app project: đọc ô tròn
trong slide
○ Data Security: Sensitive data is protected from unauthorized changes or
unintended errors .Example: A user's password can only be updated after
validation.
○ Access Control: Define rules for how data is used or modified. e.g.,
validating that the product price is never negative.
○ Improved Maintenance: Logic updates can be made internally without
affecting other parts of the program. Simplifies debugging and maintenance
by centralizing access control logic in getter and setter methods.
● Implementation in the File:
○ Well-applied: đọc ô vuông trong slide
3. Abstraction:
● Concept:
Abstraction focuses on exposing only the essential features of an object while hiding
implementation details of an object or process. The goal is to reduce complexity and
focus on the core functionality of the system.
● Importance: đọc ô tròn trước
○ Simplifies Complexity: Complex implementation details are hidden from the
user. Users only need to know what the object does, not how it does it.
○ Enhances Design: Abstraction clarifies what each class or component is
responsible for, promoting a clean design.
○ Supports Scalability: New functionalities can be added without disrupting
existing implementations, as long as they conform to the interface or abstract
class.
● Implementation in the File: đọc ô vuông. The app may have multiple views (e.g.,
home page, product page, cart page), and each view must have an initialization
process. Using an abstract method ensures that all views follow a common
initialization pattern while allowing specific implementations.
4. Polymorphism:
● Concept:
Polymorphism allows a behavior to have multiple implementations depending on the
object or context. Polymorphism allows the same operation (method or behavior) to
act differently depending on the object or class it is applied to. This makes the
system more flexible and extensible.
● Importance: đọc ô tròn
○ Flexibility: Handle multiple object types with a shared interface. The same
method name can work with different types of objects or data.
○ Scalability: Easily add new classes without modifying existing code.
○ Efficiency: A single method can operate in various ways. So it enhances
maintainability: Reduces code duplication and centralizes control.
● Implementation in the File: đọc ô vuông
● Benefits for the Project:
○ Polymorphism provides flexibility in handling diverse entities within the app:
■ Users can add items to the cart in various ways without worrying
about the underlying implementation.
■ Admins and customers perform different actions on the same
interface, leveraging the polymorphic behavior of the User class.
Overall Evaluation:
The "Online Shopping App" project has effectively applied the four OOP principles. These
principles contribute significantly by: