REPOSITORY DESIGN
PATTERN
By Shaktisen
Chaudhary
What are DESIGN PATTERN
- Design patterns are typical solutions to commonly occurring
problems in software design.
- They are like pre-made blueprints that you can customize to solve a
recurring design problem in our code.
Why to use a design patterns
- There are numerous ways to structure the code and project for our
web application, and we can put as much or as little thought as you
like into architecting.
- But it is usually good idea to follow common design patterns
because it will make our code easier to manage and easier for others
to understand.
- It also helps to speed up the development process.
What is REPOSITORY DESIGN PATTERN
- It’s one of the many design patterns available
- Repository design pattern is actually simple. It’s just the addition of
another layer into your system. The Service Layer.
- This separates out our Business with data access layer (Model layer)
making them independent of each other
REPOSITORY DESIGN PATTERN
Note: Controller comes in the business layer and Model comes in the database layer
Benefits of REPOSITORY DESIGN
PATTERN
- Easily changeable DB, let's say we are using MySQL and want to
change to MongoDB
- No need to write multiple codes.
- Business and data access layer logic can be tested separately
Without REPOSITORY LAYER
Note 2: Example of controller
(business layer) directly using
Model (database or model layer)
for its CRUD operation
REPOSITORY DESIGN PATTERN
Note: Controller comes in the business layer and Model comes in the database layer
Making of a REPOSITORY LAYER
Making of a REPOSITORY LAYER
Note: We need to bind our test
interface with test Repository
using service provider in the
register function.
Also, we need to initiate this
class in config file in order to
apply above bind
Use of a REPOSITORY LAYER
Use of a REPOSITORY LAYER
SINGLETON DESIGN
PATTERN
By Shaktisen
Chaudhary
SINGLETON design pattern
- Single pattern says a class
instance should not be
created multiple times, it
should be initialized only
once.
- It is useful when we are
making connection with
our database which should
happen only once
Making and use of SINGLETON design
pattern
- Once the instance is
created, singleton will not
allow re-connection
- So, we cannot create
multiple instances of a
class
- With the help of this
instance variable we call
to connect with our
database
References
1. https://codesource.io/brief-overview-of-design-pattern-used-in-larave
l/
2. https://www.geeksforgeeks.org/how-to-create-singleton-design-
pattern-in-php-5/
THANK YOU