0% found this document useful (0 votes)
16 views

Object Oriented

Uploaded by

Ahmed hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Object Oriented

Uploaded by

Ahmed hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Software Design

Patterns
Presented By:
Kanak Khandelwal
Ahmed Ifthaquar Hussain
Overview
About
What it provides
Guide How it helps

Software Designs
Creational
Structural
Behavioral
Overview
e-Milma Shopee
Your Milma goes online
An online shopping cart and in-house
delivery system made to make student's
life easy and pull them out from the tidious
process of standing in queues
What it provides
A list of all prodcuts in the Retail shop
What it Provides
A list of all food items in the Cafe
What it Provides
Efficient Cart System
What it Provides
Final Order Overview
What it provides
Delivery to any location inside the campus
What it provides

Order Tracker
What it provides

Order Tracker
What it provides
An online queue to replace the token system
What it provides
An online queue to replace the token system
Deliverer’s Dashboard
Admin’s Dashboard
Admin’s Dashboard
How it helps
During exams
If you fall sick

During fests and events


Saves you from becoming a delivery guy for
your friends
Before E-Milma Shoppee After E-Milma Shoppee

https://github.com/Kanak0202/e-Milma-Shopee.git
Software Designs
Software Designs Used
Creational:
Factory Method

Structural:
Decorator

Behavioural:
Chain of Responsibility
State
Creational Design
Pattern
Factory Method
Abstract
Our project employs the Factory Method design pattern to
efficiently manage the creation of different user types. This
pattern centralizes object creation, promoting flexibility and
code reusability. By implementing the Factory Method pattern,
we've streamlined the process of creating Customer, Admin,
and Deliverer users, each tailored to their specific roles.
Implementation
Within our project, the User class acts as the
superclass for different user types. By
implementing a virtual create_user method in the
User class, subclasses such as Customer, Admin,
and Deliverer can override this method to
instantiate objects tailored to their roles.
Factory Classes
Customer, Admin, and Deliverer Classes:
Each subclass overrides the create_user method to initialize
attributes specific to their roles. For instance, the Customer
class initializes customer-related attributes like
roll_no,hostel,room_number while the Admin class sets
administrative privileges, and the Deliverer class configures
delivery-related attributes such as aadhar number and
address.
Factory Classes
Behavioural Design
Pattern
Chain of Responsibility
Introduction
The Chain of Responsibility pattern is a behavioral design pattern where
a request is passed through a chain of handlers. Each handler has the
ability to process the request or pass it to the next handler in the chain.
If a handler cannot handle the request, it delegates it to the next handler
in the chain until the request is processed or the end of the chain is
reached.
Chain of Responsibility
Key Components:

1. BaseHandler Class:
Base class defining the structure for all handlers.
Contains an abstract method, handle_request(), which must be implemented by concrete
handler classes.
2. Concrete Handler Classes:
UsernameValidationHandler: Validates the username provided by the user.
EmailValidationHandler: Validates the email provided by the user.
PasswordValidationHandler: Validates the password provided by the user.
PhoneNumberValidationHandler: Validates the phone number provided by the user.
3. Chain Construction:
Handlers are linked together in a chain.
Each handler holds a reference to the next handler in the sequence.
Chain of Responsibility Steps:
User Registration (Chain_of_Responsibility)
Chain_Of_Responsibility
Chain_Of_Responsibility
State Design Pattern
Introduction

The State Design pattern is a behavioral design pattern that allows an


object to alter its behavior when its internal state changes. This
pattern enables objects to switch between different states seamlessly,
encapsulating state-specific logic within individual state objects. By
decoupling state transitions from the object's behavior, the State
pattern promotes flexibility, maintainability, and scalability in software
systems.
State Design Pattern
Why we used?

The code separates the behavior of an order into individual state classes,
making it easier to manage and extend the logic for different states. This
pattern promotes modularity, maintainability, and flexibility in handling
the lifecycle of an order in our milma system.
State Design Pattern
Implementation: Step1

Create state classes representing different states of an order, such


as PendingState, PackingState, AssignedDelivererState, and
OutForDeliveryState. These classes inherit from a common base
class (OrderState) and implement a method
transition_to_next_state() to transition the order to the next state.
State Design Pattern
Implementation
State Design Pattern
Implementation: Step2

Implement State Transition Logic:

In each state class, implement the transition_to_next_state()


method to update the order's status and perform any necessary
actions based on the transition. For example, in the PackingState,
the method updates the order status to 'Packing' and assigns a
deliverer to the order.
State Designs
Implementation
State Designs
Implementation Step 3

1.) Integrate States with Model:

In the Order model, define a method transition_to_next_state() to


facilitate state transitions. This method delegates the transition
logic to the current state object retrieved based on the order's
current status.
State Designs
Implementation Step 3

2.) Retrieve Current State:

Implement a method get_current_state() in the Order model


to determine the current state object based on the order's
status. This method returns an instance of the appropriate
state class corresponding to the order's current state.
State Designs
Implementation Step 3
3.) Perform State Transitions:

Whenever a state transition is required (e.g., when an action


triggers a change in the order status), call the
transition_to_next_state() method on the Order model instance.
This method internally delegates the transition logic to the
current state object.
State Designs
Implementation Step 3
State Designs
Implementation Step 4

Use in Views or Business Logic:


In views or business logic, call the
transition_to_next_state() method on the Order model
instance to transition the order to the next state based on
specific conditions or user actions.
Structural Designs
Pattern
Decorator
Introduction

Decorators in software development are a design pattern used to modify


or extend the behavior of functions or classes without directly altering
their code. By applying decorators to functions or classes, additional
functionality such as authentication, logging, or parameter validation can
be seamlessly added. This promotes code reusability, readability, and
maintainability by separating concerns and enabling modular and flexible
design.
Decorator
Implementation

unauthenticated_user(view_func):
This decorator checks if the user is already authenticated.
If the user is not authenticated, it redirects them to the home page ('/').
If the user is authenticated, it allows them to access the view.
Usage: Applied to views that should only be accessible to authenticated users,
such as checking out and placing an order.
Decorator
Implementation

allowed_users(allowed_roles):
This decorator checks if the authenticated user belongs to a specific role (group).
It takes a list of allowed roles as an argument.
If the user belongs to one of the allowed roles, it allows them to access the view.
If the user does not belong to any allowed role, it returns an "Unauthorized"
message.
Usage: Applied to views that should only be accessible to users with specific
roles, such as checkout page can be accessed by customer and admin but not by
deliverer.
Decorator
Implementation

admin_only(view_func):
This decorator restricts access to views based on the user's role (group).
It checks if the authenticated user is an admin.
If the user is not an admin, it redirects them to the home page ('/').
If the user is an admin, it allows them to access the view.
Usage: Applied to views that should only be accessible to admin users,
such as administrative dashboard pages.
Thank You

You might also like