3

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 great if someone could point me to the starting reference document or so.

Thank you so much in advance.

Name is Nilay
  • 2,743
  • 4
  • 35
  • 77
Pruthvid
  • 683
  • 10
  • 19
  • similar question: http://stackoverflow.com/questions/6245722/android-design-patterns – Ray Tayek Aug 24 '11 at 02:29
  • @Ray that discusses the design pattern to use in application development. I am talking about GoF design patterns that are used in Android apis. How android use it internally to solve some purpose. – Pruthvid Aug 24 '11 at 02:37
  • 1
    Android is open source. So get the source, pick a package or two, read the code and spot the patterns. The purpose or your homework is for you to do some work and learn something, not get ready answers on SO. – Nikolay Elenkov Aug 24 '11 at 02:43
  • @Nikolay I am not asking anyone to do my homework. I am saying that if i could get a headstart to the packages in which some of the GoF patterns are used then i can start my study from that package directly or some online android reference document where they might have listed where they have used what as it is a week homework only and i dont want to get into wrong packages and waste time so i have asked for just a starting point only. – Pruthvid Aug 24 '11 at 17:48
  • 'Wasting time' is a way to learn too, by mistake. Here's the [reference](http://developer.android.com/reference/packages.html). I don't think there is a reference doc about the patterns, but you might find a high-level overview of the platform to get you started. – Nikolay Elenkov Aug 25 '11 at 01:09

2 Answers2

1

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.

Dave Sims
  • 5,060
  • 3
  • 24
  • 26
0

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.

Community
  • 1
  • 1
sivi
  • 10,654
  • 2
  • 52
  • 51