开发者

Design patterns used in Android apis

We have a class home work for design pattern class. In that we have to explain anyone design pattern used in any api/framework. I was thinking if I could do the same using Android apis. I know that android uses some command, observer, template method patterns and many more but it would be gr开发者_开发问答eat if someone could point me to the starting reference document or so.

Thank you so much in advance.


Frameworks almost by definition tend to implement high-level patterns such as MVC or ORM patterns. These are not covered in the GOF text, although you will find them in other pattern books such as Martin Fowler's Patterns of Enterprise Application Architecture. Some GOF patterns are implemented at the framework or even language-level (like C# events/delegates as an example of the Observer pattern), but mostly GOF patterns are left to the individual developer to implement as needed, as the details tend to be application or domain-specific.

Android is the same way. It has a specific flavor of Model-View-Controller built in, but not too many GOF-specific patterns. You might consider the Activity lifecycle callbacks (onStart, onResume, etc.) as a kind of Observer pattern, although with only one dedicated subscriber.

Another example might be AsyncTask, which could be considered a species of the Command Pattern. I'll leave it to you to make the connection. It is homework after all.


This link show How extensive is the use of design patterns in Java core. I will expect the android to use them extensively as well.

Examples of GoF Design Patterns in Java's core libraries

And see how Adapter pattern Specifically is being used in the Android frame (second example is from Android's source code)

http://javatechig.com/design-patterns/adapter-design-pattern-in-java

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/widget/Adapter.java?av=f

Design Patterns are just conventions which made to simplify coding. And make it more clear so you should make sure that is what they do and not obscurify your code structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜