Common Design Patterns In Android
- Builder Pattern
- Observer Pattern
- Strategy Pattern
- Adapter Pattern
✅ What is the definition of Design Pattern?
Design patterns are used to represent some of the best practices adapted by experienced object-oriented software developers. In software development, a design pattern is a general reusable solution to a commonly occurring problem or task in software design.
✅ Benefits of using Design Patterns in Android ?
1.Design Patterns use object-oriented concepts such as decomposition, inheritance, and polymorphism.
2.They can improve the re-usability and extensibility of Android apps. It means you do not need to write the same code again at various places, and also you can be able to add other features to your app much more easier than general coding. Therefore, Design Patterns can increase speed in application development in Android.
- They can make your codes cleaner by decoupling the code. In addition, Design Patterns can enhance the understanding of codes in Android apps.
4.Design Patterns are proved and testified solutions because they have been built upon the knowledge and experience of expert application developers.
5.They make communication between developers more efficiently.
✅ Types of Design Patterns ?
1.Creational Design Pattern (Builder,Singleton,DI Patterns)
They are concerned with the way of creating objects such as Builder, Singleton, and Dependency Injection.
- Structural Design Pattern (Adapter pattern)
They are discussed how classes and objects can be composed, to form larger structures such as Adapter, Facade, and Proxy.
- Behavioral Design Pattern (Observer,Mediator, and Interpreter and strategy )
They are considered the interaction and responsibility of objects such as Observer, Mediator, and Interpreter.
✔ Builder Pattern : ex AllertDialog.Build()
indicates that you should construct a complex object from simple objects
by using step-by-step approach. It is mainly used when object cannot
be implemented in single step like in the deserialization of a complicated object.
adv: 1-you do not need to have all the data to pass it to your object.
2-implements a clear separation between the construction and representation of an object.
3-It handles the changes in the internal representation of objects.
4-It can improve the flexibility and readability of source codes.
✔Adapter Pattern
used for class and object composition. This pattern is useful in situation
when we have two different interfaces, we want to combine them and we can’t change them
✔Observer Pattern
gives us the way to communicate between different classes and objects.
This pattern is the best approach if we have one-to-many relation
and we’d like to inform other objects about some changes or actions.
✔Strategy Pattern
Strategy design pattern takes place when you need to implement behaviour or plan. in android using this pattern for aset of data like filteration data or doing actions on data without writle complex code or more if .. else.