Android - Design Patterns
Why design patterns are important??
Design patterns are important for a developer because they provide a common vocabulary and a set of best practices for solving common design problems. By using design patterns, developers can communicate more effectively with their colleagues and other stakeholders, and they can create more maintainable, scalable, and reusable code.
Design patterns also help developers to avoid reinventing the wheel, and they can provide a starting point for solving new problems. Instead of trying to come up with a solution from scratch, developers can use design patterns as a foundation, and then customize and extend them to fit the specific requirements of their project.
Additionally, design patterns can help developers to improve the performance, security, and reliability of their code, and they can make it easier to test, debug, and maintain over time. By applying proven design patterns, developers can avoid common pitfalls and mistakes, and they can create more robust and high-quality software.
In short, design patterns are an essential tool for any developer who wants to create effective and efficient software solutions. By learning and applying design patterns, developers can improve their skills and advance their careers.
Interface Pattern
An interface defines the signature operations of an entity, it also sets the communication boundary between two entities, in this case two pieces of software. It generally refers to an abstraction that an asset provides of itself to the outside.
For Example, we want to send some messages across the system. The interface defines a single method to send a message:
public interface Messenger {
public void sendMessage(String receiver, String text);
}
and classes can have their own implementation of this function, like either they can send a mail, or it could also just be printed to stdout.
ViewHolder pattern
The ViewHolder design pattern enables you to access each list item view without the need for the look up, saving valuable processor cycles. Specifically, it avoids frequent call of findViewById() during ListView scrolling, and that will make it smooth.
ViewHolder design pattern is used to speed up rendering of your ListView - actually to make it work smoothly. Your code might call findViewById() frequently during the scrolling of ListView, which can slow down performance. Even when the Adapter returns an inflated view for recycling, you still need to look up the elements and update them.
Dependency Injection -
The Dependency Injection pattern is used in almost every framework and is based on the "inversion of control" (IoC) principle. It relates to the way in which an object obtains references to its dependencies - the object is passed its dependencies through constructor arguments or after construction through setter methods or interface methods. It is called dependency injection since the dependencies of an object are 'injected' into it, the term dependency is a little misleading here, since it is not a new 'dependency' which is injected but rather a 'provider' of that particular capability. For example, passing a database connection as an argument to a constructor instead of creating one internal would be categorized as dependency injection.
The pattern seeks to establish a level of abstraction via a public interface and to remove dependencies on components by supplying a 'plugin' architecture. This means that the individual components are tied together by the architecture rather than being linked together themselves. The responsibility for object creation and linking is removed from the objects themselves and moved to a factory.
Repository Pattern -
The repository pattern is a design pattern that isolates the data layer from the rest of the app. The data layer refers to the part of your app, separate from the UI, that handles the app's data and business logic, exposing consistent APIs for the rest of your app to access this data.
Repository pattern implements separation of concerns by abstracting the data persistence logic in your applications.
Real Life Problem and class design
- Functional Requirements
- Non-Functional Requirements
- Assumptions
- Client Server Communication
- API Design
- Data Models
- App Flow
- Performance
- Accessibility
- Internationalization/Localization
- Security
.....To Be Continued....
Comments
Post a Comment