The best way to learn to code is to code. But, to write good code, you will also have to read good code. Make a habit of reading good code. You can find many open-source projects on GitHub and start reading.
You can learn many design patterns by looking at the source code of the open-source libraries you use regularly.
Retrofit
Builder Pattern → Retrofit . Builder
Proxy Pattern → Retrofit . create(Class<T>)
Adapter Pattern → CallAdapter
Factory Pattern → CallAdapter . Factory
Glide
Builder Pattern → Glide . with(context) . load(url) . into(imageView)
Factory Pattern → ModelLoaders, ResourceDecoders
Strategy Pattern → DiskCacheStrategy . ALL, DiskCacheStrategy . NONE, etc.
Singleton Pattern → Single Glide instance per app
Observer Pattern → Glide observes lifecycle changes using LifecycleListener
More Examples
Builder Pattern
Separates the construction of a complex object from its representation by using chained method calls to build the object step by step.
Example: AlertDialog . Builder and NotificationCompat . Builder
Adapter Pattern
Converts an interface into another that the client expects.
Example: RecyclerView . Adapter
Observer Pattern
Allows objects to subscribe to changes in another object.
Example: Coroutines Flow API, LiveData and BroadcastReceiver
Factory Pattern
Encapsulates object creation to promote loose coupling
Example: ViewModelProvider . Factory
Watch the video: How to read the code of open-source projects?
That’s it for now.
Thanks
Amit Shekhar
Founder, Outcome School