Saturday 25 April 2015

HB Blog 69: Design Patterns In Mobile Development - Android/iOS.

Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.
Generally, In mobile applications where user interface is most important aspect of development as a developer MVC design pattern is most commonly heard. But, a developer uses multiple design patterns that are suitable for that process and phase. Android latest developed version lollipop as well as devices wearable are more concentrating on design patterns that can make application more resuable and standardize. 

There are many design patterns that used in mobile development. In this post I would try to put how does design pattern are used in Android and iOS mobile development.

Model-View-Controller (MVC) is a software architectural pattern for implementing user interfaces. In Android, database or preferences are model, UI created in xml file is view and java file coding logic is controller. Similarly, in iOS, database or core data is model, UI created in xib or storyboard is view and .m or .h files acts as controller. In MVC pattern most important aspect is that model never communicates with view directly, always controller acts as a middle man.

Singleton design pattern is another important design pattern used in mobile development. In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. In Android, extending application class makes the class singleton. In iOS, sharedInstance is used to return singleton object.

Delegation pattern is a design pattern in object-oriented programming where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object. In Android,
delegation pattern is not directly used but we find it during our listeners(onclick, ontouch, etc.) as well as during startActivityForResult(). In iOS, delegation is most excessively used concept during predefine delegates such as UITextFieldDelegate, etc. as well as custom made delegates.

Observer design pattern in which an object maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. In Android, we hav observer class also observer is seen during LocationListener method onLocationChange() which observes change in location and updates the latitude and longitude. Broadcase reciever is also a part of these pattern. In iOS, Observer is seen in notification as well as KVO(Key-Value Observing).  

Adapter pattern help us to translate one interface to a compatible one. In Android, we can see these pattern during listview adapter such as array adapter, list adapter, cursor adapter, etc. In iOS, we have UITableViewDelegate, UIScrollViewDelegate, etc using adapter design pattern.

No comments:

Post a Comment