CSC/ECE 517 Fall 2009/wiki3 21 MobileDesignPattern: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Obtain useful format from wiki2)
 
(63 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Design Pattern for Mobile Applications ==
The popularity and number of mobile applications rising quickly.  Design patterns can help make the development process more efficient.  While almost any design pattern could be used within mobile applications, certain patterns are well suited for the unique environment of mobile applications.  This wiki explains the mobile application environment, then focuses on design patterns that work well within this new emerging environment.


== Design Pattern for Mobile Applications ==
__TOC__


[http://en.wikipedia.org/wiki/Service-oriented_architecture ''Service Oriented Architecture'' 3] (or SOA) describes how to design a software system and connect the separate components using services.  Reflection and metaprogramming are two powerful concepts that directly support the principles of SOA.  This article covers the following goals:
== The Mobile Application Environment ==
#Provides a simple understanding of reflection, metaprogramming, and SOA's.
#Explains how these concepts are interrelated, specifically how reflection and metaprogramming support SOA's.


== '''Service Oriented Architecture (SOA), Reflection, and Metaprogramming''' ==
The emerging mobile application environment presents many unique opportunities and challenges for developers.  It seems almost everyone has a cellphone, blackberry, or other small portable device.  These devices are "getting smarter" in that many people are developing new applications for them.  Cell phones are no longer only used to call people, they often have features like text messaging, cameras, video games, web browsers and more.  There is much opportunity for developers to write new applications for mobile devices.


__TOC__
While opportunity abounds, there are also quite a few challenges.  Mobile applications have fewer resources than are typically found in other development environments.  The screen on mobile devices is typically smaller and there is usually not a keyboard and mouse (user inputs are reduced) [5].  CPU resources are generally lower than those found in the typical environment [7].  Power usage is also limited because batteries are usually the power source, so reducing power use by the application is an important goal [7].  Connections are typically expensive and are often prone to loss of signals [6].


=='''An overview of the concepts'''==
Another problem is that there is a high demand for applications to be developed quickly [7].  The mobile environment is changing rapidly [2].  Some of the lower level programming languages were useful because they produced fast applications, but they took too long to develop with[http://www.umsl.edu/~subramaniana/concepts1.html 12].  Now, with the increased demand for applications quickly, Object Oriented Programming (OOP) is used more often.  While this causes a greater usage of resources, this is outweighed by the benefits of much quicker development cycle and the re-use of code.  In particular, good solutions may be re-used in Object Oriented Programming (OOP) [7].


==='''Service Oriented Architecture'''===
In the mobile environment, applications are often written on different operating systems [http://en.wikipedia.org/wiki/Mobile_operating_system] on different mobile systems.  There is increased interaction between mobile systems, especially for cell phones.  The Service Oriented Architecture design pattern is especially well suited for this situation.  This is a fairly new field, and methods are currently being developed to aid developers.


[http://en.wikipedia.org/wiki/Service-oriented_architecture ''Service Oriented Architecture''] (or SOA) is a concept in computing that defines the interaction of different software in terms of protocols and functionality.  A SOA can be viewed as containing multiple services which may be linked as desired by protocols.  The SOA is designed so that each functional unit of software in a system is isolated from each other and provides a service without directly making [http://en.wikipedia.org/wiki/Subroutine subroutine calls] to each other.  This is generally accomplished by passing messages. [http://en.wikipedia.org/wiki/Service_oriented_architecture 3]
== Ways to Adapt Using Design Patterns ==


SOA offers the following technical advantages:
Several principles and patterns have been recognized and further developed in coding for mobile applications.  Many of these methods are still undergoing change and experimentation.  There are new methods being developed and others left behind.  A design pattern can be defined as a repeatable solution to a common problem in software.  It is a template for how to solve the problem, not actual code [7].
*Offers services across platforms
*Allows services to be split across systems and networks
*Allows services to be location independent and close to their business units
*Provides a bridge between incompatible technologies
*Leverages existing technologies
*Reduces dependency on custom systems


The information being used to communicate between services must contain data, sufficient detail about the characteristic of the data and must remain independent of the underlying platform and programming languageAlthough SOA does not specify the format to transfer data, programmers have generally used XML for this purposeFurthermore, [http://en.wikipedia.org/wiki/Metadata Metadata] (data that describes the actual data) [http://en.wikipedia.org/wiki/Metadata 6] in the SOA must:  [http://en.wikipedia.org/wiki/Service_oriented_architecture 3]
Ease of navigation is a particularly important principle, because of the reduced number of user inputs (for example, buttons from 0 to 9 instead of a mouse and keyboard)Everything in an application should be no more than three clicks away.  If a program is too "deep", requiring many clicks, this will be a problem because it takes longer to navigate on a mobile deviceIf the application is to "broad" as in too many links on one page, the data may not all fit on the screen. One way to mitigate this problem is to reduce functionality, to keep the application as simple as possible [5].


*Be easy to configure
*Provide an easy way to discover services
*Provide an easy way to incorporate services
*Remain coherent
*Preserve data integrity
*Be easy to manage


A simple example of metadata is a README file that specifies the inputs and outputs to a programThe inputs and outputs of the program would be the data, and the README file is metadata that describes this data.
The [http://www.javaworld.com/javaworld/jw-10-2005/jw-1003-mvc.html Model View Controller] pattern [1] fits the mobile environment well.  Models may be set up so that optimum data structures are used, as was discussed for the EC Factory pattern [7]Efficient designs may be built into the controllers.  Views may be standardized for the application to handle the small screens.


SOA does not limit the protocol used to transfer the data.  A wide variety of technologies can be used including [http://en.wikipedia.org/wiki/SOAP_(protocol) SOAP], [http://en.wikipedia.org/wiki/Representational_State_Transfer REST] and [http://en.wikipedia.org/wiki/Remote_procedure_call RPC].  This is generally left for the programmer of the system.
We will now discuss few important ones.<br>


[[Image:SOA_Example.jpg]]


We created this simplified image to illustrate the basic principles of service oriented architectures. 
Two major design patterns that have come up to help in mobile software and to address the above discussed issues in a mobile device are : Energy Conscious design pattern and Mobile agent design pattern
* Services may be used by multiple applications.
* Services do not call on each other.
* Services communicate via protocols.
* An example protocol is provided, in which the application passes x to the Sin function, and Sin(x) is returned.
* Because of the protocol link, services may be written in different programming languages, or even be hosted on different computers with different operating systems, which allows for great flexibility.


==='''Metaprogramming'''===
=== Energy Conscious Factory Design ===
According to the research published in ''[10]''


[http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is the writing of computer programs that write other computer programsThis allows the programmer to complete tasks faster than if (s)he had to code everything manuallyA [http://en.wikipedia.org/wiki/Compiler compiler] is an excellent example of a metaprogram. It allows the programmer to code in a higher level language and then the compiler will convert that program into machine language. [http://en.wikipedia.org/wiki/Metaprogramming 7]
Power consumption has not been much of a concern to developers in the past, but this is important in the mobile environmentBattery power on cell phones is limited.  [7]  To cope with this:
- Use registers instead of memory whenever possible (registers use less energy)
- Use structs instead of classes
- Use static instead of dynamic


:*'''''Example''': Metaprogramming in Ruby [2]  
Some strategies and their experimental results are discussed in [10]:<br>
  class Person
[[Image:ECFactory_Fig8.jpg| General Strategies]]
    attr_accessor :name
  end


In the example above, attr_accessor is used to create [http://en.wikipedia.org/wiki/Mutator_method 'setters' and 'getters'] for the name attribute via metaprogrammingFrom this statement, code is automatically generated that provides a function to write the name (setter) and a function to read the name (getter).
'''''Factory Method pattern''''' is a pattern that returns an object from one of various possible classesWhich class is chosen to be an object generator  is  depended  on  data  provided  to it. 
The Factory Method Pattern is a good pattern to build upon for the energy conscious pattern.<br>
Lets look at both versions.<br>
Class Diagram of sample Factory Method pattern:


:*'''''Example''': Metaprogramming in Ruby [http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox 9]  
[[Image:ECFactory_Fig1.jpg|Class Diagram of sample Factory Method pattern ]]
  Array.send(:define_method, :ducky) { puts 'ducky' }


This example does something particularly interesting.  At run time, it defines a new method called ducky that prints out the word "ducky".  This line modifies the program at run time!
Sequence Diagram (with Activations) of sample Factory Method pattern:


Another example in Ruby is the ActiveRecord library.  It dynamically creates accessor methods that map directly to each column in the database.
[[Image:ECFactory_Fig2.jpg|Sequence Diagram (with Activations) of sample Factory Method pattern ]]


:*'''''Example''': ActiveRecord metaprogramming in Ruby [10]
  class Movie < ActiveRecord::Base
  end


  movie = Movie.create
'''''Modified  Factory  Method  pattern'''''
  movie.title = "Doctor Strangelove"
As regular Factory Method pattern was not designed for being energy concerned, so, it is slightly modified. Some of the critical tweaks are:
  movie.title                          # => "Doctor Strangelove"
*Factory Method Pattern that mixes usage of struct and class in several manners.
*Factory Method Pattern that uses a static factory method in the Factory struct.  
*Factory Method Pattern that applies generics principle which is parametered type.  
*Factory Method Pattern That Uses ConcreteProduct Class, ConcreteCreator Struct with Non-Static FactoryMethod().


In the example above, we create a new instance of Movie, which subclasses ActiveRecord. We then directly access the database's title column using the setter method 'title=' and then the getter method 'title'.  These methods are not defined anywhere in the source code, but instead, ActiveRecord automatically defines them based on the database column.
The Modified Factory Method Pattern applies both struct and class recommendations.


==='''Reflection'''===
''The Factory Method Pattern that uses ConcreteProduct Class, ConcreteCreator Struct with Non-Static FactoryMethod():''


[http://en.wikipedia.org/wiki/Reflection_(computer_science) Reflection] is a specific type of meta-programming and emphasizes dynamic program modification.  It is the ability of a programming language to inspect its own code and can therefore be used to extend the language beyond its usual capabilities.  For example, it is possible to use reflection to inspect an object for a desired function and execute it dynamically.
[[Image:ECFactory_Fig3.jpg|Class Diagram of Factory Method pattern]]


:*'''''Example''': Reflection in Perl [http://en.wikipedia.org/wiki/Reflection_(computer_science) 5]
In this case, we use VehicleChooser which is a ConcreteCreator, which is a struct, while Car, Plane and Ship (which are ConcreteProduct as is a class). Method ChooseVehicle(...) which is a FactoryMethod() is non-static.
  # without reflection
  my $foo = Foo->new();
  $foo->hello();
   
  # with reflection
  my $class  = "Foo";
  my $method = "hello";
  my $object = $class->new();
  $object->$method();


In the example with reflection, $object and $method can be viewed by the program and even changed at run time.  This allows the program to change its own behavior.  This is an example of reflection because the program can see itself and change itself.
''The Factory Method Pattern that uses ConcreteProduct Struct, ConcreteCreator Struct with Static FactoryMethod():''


:*'''''Example''': Reflection in Ruby [http://en.wikipedia.org/wiki/Reflection_(computer_science) 5]
[[Image:ECFactory_Fig4.jpg|Class Diagram of Factory Method pattern]]<br>
If we use the static method appropriately, CPU workload will be reduced.  This affects directly in lessening power consumption as a whole.


  # without reflection
'''''Experimental Result:'''''
  Foo.new.hello
<br>For various combination shown in figure, the tests were run, and the result obtained are shown in the graph below.
<br><br>''Characteristic of components in each combination:''
  # with reflection
[[Image:ECFactory_Fig5.jpg|Characteristic of components in each combination ]]<br>
  Object.const_get(:Foo).new.send(:hello)


In this example, the first and second lines illustrate how the code is written without reflection.  The first line is a comment, and the second line is the actual code.  The code calls on Foo.new.hello, which calls on the object Foo, method new, and from what is returned on that, calls the method hello.  The second section does practically the same thing, but with reflection.  The main difference is that the object called by :hello can be determined at run time.
''CPU Usage Comparison:''


:*'''''Example''': More Reflection in Ruby [http://www.ruby-doc.org/core/classes/ObjectSpace.html 8]
[[Image:ECFactory_Fig6.jpg|CPU Usage Comparison ]]<br>
UPT is utilized processor time and TPT is total processor time


  ObjectSpace.each_object(Numeric) {|x| p x }
<br><br>''Energy Usage Comparison:''


In this example, Ruby can determine all the objects that are defined.  This particular line of code prints out all the numeric objects that are currently defined.
[[Image:ECFactory_Fig7.jpg|Energy Usage Comparison]]<br>


=='''How metaprogramming and reflection enhance SOA'''==
It is observed that the optimum Energy Concerned Factory Method Pattern can be obtained from the combination of ConcreteProduct classes and the ConcreteCreator struct with the static FactoryMethod(). The ECFactory Method Pattern consumes less CPU time than the regular Factory Method  Pattern (around  11%), which is is better than the worst case around 80%.  The bigger the ConcreteProduct type size is, the more range between the best and the worst case in terms of energy consumption will be.  This pattern saves energy.


Service-oriented Architecture is enhanced when the underlying programs are able to dynamically adapt to the data received. Metaprogramming and Reflection make this possibleTo see how this is so, it will be helpful to look at a few potential uses.
===Service Oriented Architecture ===
Service Oriented Architectures are well suited for the mobile environment [3].  Within this architecture, applications can make use of various services by sending messages to them via a protocol.  Applications may interact with services on operating systems and written in different languages, as long as the protocol is followed. Services may be located on different mobile devicesThis protocol is a good fit, allowing applications to reach out to services on other mobile devices, even though they may be on very different devices.


One such use would be a service that writes code based on the inputs.  The services within SOA make use of the data passed to them.  When the passed data represents code, for example 'print "Hello World"' in a language independent way, the receiving service could use metaprogramming to write code to just that.  The service would then use reflection to determine what methods are available, in our case 'print', and would perform that task.  If the service logic was to "repeat 3 times", then the code would ultimately print "Hello World" that number of times.  XML may be used to transfer this message as follows:
''Example of a SOA:''


:*'''''Example''' XML Data:
[[Image:SOA_Example.jpg]]


  <message>
===Meeting pattern Example===
    <method>print</method>
According to the research published in [6]. <br>
    <data>Hello World</data>
The meeting pattern is especially useful in mobile environments.  One device or application serves as the meeting manager.  The meeting manager coordinates and tracks the other agents (programs or applications).  These agents communicate with the oversight of the meeting manager.  Agents may be located on different devices, even on computers with more resources.  This is especially well suited for the mobile environment because it is a good way to manage the communications and relatively small applications.  A further benefit of the meeting pattern is that mobile applications may be combined (somewhat in the fashion of parallel computing) to do more and provide more resources [6].
  </message>


A more practical use of reflection and metaprogramming in a SOA would be a service that checks code for security holes.  The code could be sent to the service via whatever protocol is chosen.  This service could use reflection to examine the code.  Next, the service would evaluate the code for common security flaws.  If the program is determined to be safe enough, the service may run the code in a safe environment and perform further testing.  The service would output the results of the analysis, and perhaps even output an auto-corrected program upon completion.
''Meeting pattern Example:''


Compilers are a good current illustration of metaprogramming and reflection working in a service.  The compiler may be viewed as a service within a SOA.  It can be run on many different systems, which is a major benefit of SOA's.  Data (the code) is sent to a service (the compiler) which then translates it to machine code for the particular system.  Metaprogramming is at work here, because each line of code is generally used to write one or more lines of machine code (code directly executable by the computer).  The code and compiler effectively write a new program in machine code.  Reflection may take place when symbols generated by one section of code are referenced by another section of code. [http://dvanderboom.wordpress.com/2008/11/06/programming-language-directions/ 11]
[[Image:MCFigure3.jpg]]


A pattern emerges when studying these examplesMetaprogramming and reflection are generally used within the service to enhance the capability of the service.  The data passed to the service is often what guides how metaprogramming and reflection take place.
The master slave pattern is similar to the meeting pattern.  Instead of a meeting manager and agents, there is a master that creates, uses, and destroys slave objects.  The master assigns the slaves tasks to complete.  Like agents in the meeting pattern, slaves may be located on different mobile devices, or even on computers that have more resources.  The master / slave pattern is very useful for performing actions in parallel on different mobile devices [6].


=='''Conclusion'''==
== Conclusion ==
In conclusion, certain design patterns are especially useful in the mobile design environment.  These patterns help developers to produce applications quickly and applications which make efficient use of the limited resources in the mobile environment.  Most design patterns can be of benefit to mobile applications, but certain patterns have features that are especially well suited.  The EC factory pattern was designed for the mobile environment to reduce energy use [7].  A few other patterns show much promise with mobile devices, including the meeting pattern, master / slave pattern, and service oriented architectures.


SOA is an evolution of distributed computing based on web services.  It is an attractive solution for companies since it is platform independent allowing different software and hardware to communicate together easily.
== References ==


Metaprogramming and reflection are programming styles used to take advantage of the features in dynamic programming languages. They provide a great advantage when used in the development of SOAs to allow the services to dynamically change and adapt to the messages being passed between services.  
1. http://www.javaworld.com/javaworld/jw-10-2005/jw-1003-mvc.html - Model View Controller Architecture


=='''References'''==
2. http://patterns.littlespringsdesign.com/index.php/The_mobile_challenge - Challenges of the Mobile Environment
'''
1. http://www.service-architecture.com/web-services/articles/service-oriented_architecture_soa_definition.html - Brief explanation of SOA


2. Thomas, Dave (2006). ''Programming Ruby, The Pragmatic Programmers' Guide''.
3. http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki2_17_va - Service Oriented Architecture


3. http://en.wikipedia.org/wiki/Service_oriented_architecture - A very detailed explanation of SOA
4. http://wiki.forum.nokia.com/index.php/Understading_Desing_Patterns - Understanding Design Patterns


4. http://www.javaworld.com/javaworld/jw-06-2005/jw-0613-soa.html - A more easy to understand explanation of SOA
5. http://dev.opera.com/articles/view/designing-and-developing-mobile-web-site/ - Designing and Developing mobile web sites in the real world


5. http://en.wikipedia.org/wiki/Reflection_(computer_science) - Explanation of reflection
6. Emerson F.A Lima, Patrícia D. L. Machado, Fláavio R. Sampaio, and Jorge C. A. Figueiredo. ACM SIGSOFT Software Engineering Notes.  Volume 29, issue 3 ISSN: 0163-5948 http://portal.acm.org/citation.cfm?id=986710.986726 Universidade Federal de Campina Grande, Paraíba, Brazil, May, 2004.


6. http://en.wikipedia.org/wiki/Metadata - Explanation of metadata
7. Kayun Chantarasathaporn, Chonawat Srisa-an. ACM International Conference Proceeding Series; Vol. 270 Proceedings of the 3rd international conference on Mobile technology, applications & systems SESSION: Mobile applications, article 29. ISBN:1-59593-519-3 http://portal.acm.org/citation.cfm?id=1292331.1292364 Bangkok, Thailand, 2006


7. http://en.wikipedia.org/wiki/Metaprogramming - Explanation of metaprogramming
8. WIM Workshop,Uppsala, 17.9.2004


8. http://www.ruby-doc.org/core/classes/ObjectSpace.html - Explanation of the ObjectSpace command in Ruby
9. Mobile Application Development, Sam Nasr , www.CleavelandDotNet.info


9. http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox - Explanation of tools that Ruby provides for metaprogramming
10. Energy Conscious Factory Method Design Pattern for Mobile Devices with C# and Intermediate Language, by Kayun Chantarasathaporn  and Chonawat Srisa-an, Ph.D. at  Faculty of Information Technology,  Rangsit University, Thailand.


10. Perrotta, Paolo (2009). ''Metaprogramming Ruby''.
11. http://www.codeproject.com/csharp/structs_in_csharp.asp


11. http://dvanderboom.wordpress.com/2008/11/06/programming-language-directions/ - Illustrates the use of a compiler as a service
12. http://www.umsl.edu/~subramaniana/concepts1.html

Latest revision as of 03:44, 23 November 2009

Design Pattern for Mobile Applications

The popularity and number of mobile applications rising quickly. Design patterns can help make the development process more efficient. While almost any design pattern could be used within mobile applications, certain patterns are well suited for the unique environment of mobile applications. This wiki explains the mobile application environment, then focuses on design patterns that work well within this new emerging environment.

The Mobile Application Environment

The emerging mobile application environment presents many unique opportunities and challenges for developers. It seems almost everyone has a cellphone, blackberry, or other small portable device. These devices are "getting smarter" in that many people are developing new applications for them. Cell phones are no longer only used to call people, they often have features like text messaging, cameras, video games, web browsers and more. There is much opportunity for developers to write new applications for mobile devices.

While opportunity abounds, there are also quite a few challenges. Mobile applications have fewer resources than are typically found in other development environments. The screen on mobile devices is typically smaller and there is usually not a keyboard and mouse (user inputs are reduced) [5]. CPU resources are generally lower than those found in the typical environment [7]. Power usage is also limited because batteries are usually the power source, so reducing power use by the application is an important goal [7]. Connections are typically expensive and are often prone to loss of signals [6].

Another problem is that there is a high demand for applications to be developed quickly [7]. The mobile environment is changing rapidly [2]. Some of the lower level programming languages were useful because they produced fast applications, but they took too long to develop with12. Now, with the increased demand for applications quickly, Object Oriented Programming (OOP) is used more often. While this causes a greater usage of resources, this is outweighed by the benefits of much quicker development cycle and the re-use of code. In particular, good solutions may be re-used in Object Oriented Programming (OOP) [7].

In the mobile environment, applications are often written on different operating systems [1] on different mobile systems. There is increased interaction between mobile systems, especially for cell phones. The Service Oriented Architecture design pattern is especially well suited for this situation. This is a fairly new field, and methods are currently being developed to aid developers.

Ways to Adapt Using Design Patterns

Several principles and patterns have been recognized and further developed in coding for mobile applications. Many of these methods are still undergoing change and experimentation. There are new methods being developed and others left behind. A design pattern can be defined as a repeatable solution to a common problem in software. It is a template for how to solve the problem, not actual code [7].

Ease of navigation is a particularly important principle, because of the reduced number of user inputs (for example, buttons from 0 to 9 instead of a mouse and keyboard). Everything in an application should be no more than three clicks away. If a program is too "deep", requiring many clicks, this will be a problem because it takes longer to navigate on a mobile device. If the application is to "broad" as in too many links on one page, the data may not all fit on the screen. One way to mitigate this problem is to reduce functionality, to keep the application as simple as possible [5].


The Model View Controller pattern [1] fits the mobile environment well. Models may be set up so that optimum data structures are used, as was discussed for the EC Factory pattern [7]. Efficient designs may be built into the controllers. Views may be standardized for the application to handle the small screens.

We will now discuss few important ones.


Two major design patterns that have come up to help in mobile software and to address the above discussed issues in a mobile device are : Energy Conscious design pattern and Mobile agent design pattern

Energy Conscious Factory Design

According to the research published in [10]

Power consumption has not been much of a concern to developers in the past, but this is important in the mobile environment. Battery power on cell phones is limited. [7] To cope with this: - Use registers instead of memory whenever possible (registers use less energy) - Use structs instead of classes - Use static instead of dynamic

Some strategies and their experimental results are discussed in [10]:
General Strategies

Factory Method pattern is a pattern that returns an object from one of various possible classes. Which class is chosen to be an object generator is depended on data provided to it. The Factory Method Pattern is a good pattern to build upon for the energy conscious pattern.
Lets look at both versions.
Class Diagram of sample Factory Method pattern:

Class Diagram of sample Factory Method pattern

Sequence Diagram (with Activations) of sample Factory Method pattern:

Sequence Diagram (with Activations) of sample Factory Method pattern


Modified Factory Method pattern As regular Factory Method pattern was not designed for being energy concerned, so, it is slightly modified. Some of the critical tweaks are:

  • Factory Method Pattern that mixes usage of struct and class in several manners.
  • Factory Method Pattern that uses a static factory method in the Factory struct.
  • Factory Method Pattern that applies generics principle which is parametered type.
  • Factory Method Pattern That Uses ConcreteProduct Class, ConcreteCreator Struct with Non-Static FactoryMethod().

The Modified Factory Method Pattern applies both struct and class recommendations.

The Factory Method Pattern that uses ConcreteProduct Class, ConcreteCreator Struct with Non-Static FactoryMethod():

Class Diagram of Factory Method pattern

In this case, we use VehicleChooser which is a ConcreteCreator, which is a struct, while Car, Plane and Ship (which are ConcreteProduct as is a class). Method ChooseVehicle(...) which is a FactoryMethod() is non-static.

The Factory Method Pattern that uses ConcreteProduct Struct, ConcreteCreator Struct with Static FactoryMethod():

Class Diagram of Factory Method pattern
If we use the static method appropriately, CPU workload will be reduced. This affects directly in lessening power consumption as a whole.

Experimental Result:
For various combination shown in figure, the tests were run, and the result obtained are shown in the graph below.

Characteristic of components in each combination: Characteristic of components in each combination

CPU Usage Comparison:

CPU Usage Comparison
UPT is utilized processor time and TPT is total processor time



Energy Usage Comparison:

Energy Usage Comparison

It is observed that the optimum Energy Concerned Factory Method Pattern can be obtained from the combination of ConcreteProduct classes and the ConcreteCreator struct with the static FactoryMethod(). The ECFactory Method Pattern consumes less CPU time than the regular Factory Method Pattern (around 11%), which is is better than the worst case around 80%. The bigger the ConcreteProduct type size is, the more range between the best and the worst case in terms of energy consumption will be. This pattern saves energy.

Service Oriented Architecture

Service Oriented Architectures are well suited for the mobile environment [3]. Within this architecture, applications can make use of various services by sending messages to them via a protocol. Applications may interact with services on operating systems and written in different languages, as long as the protocol is followed. Services may be located on different mobile devices. This protocol is a good fit, allowing applications to reach out to services on other mobile devices, even though they may be on very different devices.

Example of a SOA:

Meeting pattern Example

According to the research published in [6].
The meeting pattern is especially useful in mobile environments. One device or application serves as the meeting manager. The meeting manager coordinates and tracks the other agents (programs or applications). These agents communicate with the oversight of the meeting manager. Agents may be located on different devices, even on computers with more resources. This is especially well suited for the mobile environment because it is a good way to manage the communications and relatively small applications. A further benefit of the meeting pattern is that mobile applications may be combined (somewhat in the fashion of parallel computing) to do more and provide more resources [6].

Meeting pattern Example:

The master slave pattern is similar to the meeting pattern. Instead of a meeting manager and agents, there is a master that creates, uses, and destroys slave objects. The master assigns the slaves tasks to complete. Like agents in the meeting pattern, slaves may be located on different mobile devices, or even on computers that have more resources. The master / slave pattern is very useful for performing actions in parallel on different mobile devices [6].

Conclusion

In conclusion, certain design patterns are especially useful in the mobile design environment. These patterns help developers to produce applications quickly and applications which make efficient use of the limited resources in the mobile environment. Most design patterns can be of benefit to mobile applications, but certain patterns have features that are especially well suited. The EC factory pattern was designed for the mobile environment to reduce energy use [7]. A few other patterns show much promise with mobile devices, including the meeting pattern, master / slave pattern, and service oriented architectures.

References

1. http://www.javaworld.com/javaworld/jw-10-2005/jw-1003-mvc.html - Model View Controller Architecture

2. http://patterns.littlespringsdesign.com/index.php/The_mobile_challenge - Challenges of the Mobile Environment

3. http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki2_17_va - Service Oriented Architecture

4. http://wiki.forum.nokia.com/index.php/Understading_Desing_Patterns - Understanding Design Patterns

5. http://dev.opera.com/articles/view/designing-and-developing-mobile-web-site/ - Designing and Developing mobile web sites in the real world

6. Emerson F.A Lima, Patrícia D. L. Machado, Fláavio R. Sampaio, and Jorge C. A. Figueiredo. ACM SIGSOFT Software Engineering Notes. Volume 29, issue 3 ISSN: 0163-5948 http://portal.acm.org/citation.cfm?id=986710.986726 Universidade Federal de Campina Grande, Paraíba, Brazil, May, 2004.

7. Kayun Chantarasathaporn, Chonawat Srisa-an. ACM International Conference Proceeding Series; Vol. 270 Proceedings of the 3rd international conference on Mobile technology, applications & systems SESSION: Mobile applications, article 29. ISBN:1-59593-519-3 http://portal.acm.org/citation.cfm?id=1292331.1292364 Bangkok, Thailand, 2006

8. WIM Workshop,Uppsala, 17.9.2004

9. Mobile Application Development, Sam Nasr , www.CleavelandDotNet.info

10. Energy Conscious Factory Method Design Pattern for Mobile Devices with C# and Intermediate Language, by Kayun Chantarasathaporn and Chonawat Srisa-an, Ph.D. at Faculty of Information Technology, Rangsit University, Thailand.

11. http://www.codeproject.com/csharp/structs_in_csharp.asp

12. http://www.umsl.edu/~subramaniana/concepts1.html