Posts

Showing posts with the label Design Patterns

Repository Design Pattern

Repository Design Pattern separates the data access layer from the business layer by adding an additional layer of abstraction between them. In repository pattern, business logic can access the data object without having knowledge of the underlying data access layer. Possible use cases for repository pattern  1. Underlying data source or data access layer need to change. 2. Hiding the complexity of data access layer.  3. Centralized handling of the domain objects. Implementation Implementation of the repository pattern include following steps  1. Create an Interface IProductRepository. 2. Add abstract methods for CRUD operation like Add(), Update(), Delete() and Get() in above interface as shown below. //Interface for product repository public   interface  IProductRepository {  Product Get(int Id);  void Add(Product entity);  void Update(Product entity);  void Delete(int Id); } 3. Create ProductRepository class which implements IProductReposi...

Abstract Factory Design Pattern

Abstract factory pattern is categorized under creational design pattern that focuses on families of related object creation without exposing its internal logic. In an abstract factory pattern, families of related objects are created without specifying their exact classes. It defines an interface for creating a set of related objects and allows different implementations of the factory to create different sets of related objects.  Possible use cases for abstract factory pattern  Here are some possible use cases for the Abstract Factory pattern 1. GUI Toolkits Abstract Factory pattern is frequently used in GUI toolkits, where different UI components like buttons, text boxes, and menus need to be created for different platforms such as Windows, Mac, or Linux. 2. Database Drivers Abstract Factory pattern can be used to create database drivers that support different databases like Oracle, MySQL, and SQL Server. The abstract factory can create a family of related objects like Co...