Software Engineering Institute | Carnegie Mellon University
Software Engineering Institute | Carnegie Mellon University

Digital Library

Javascript is currently disabled for your browser. For an optimal search experience, please enable javascript.

Advanced Search

Basic Search

Content Type

Topics

Publication Date

Presentation

Adapting View Models as a Means for Sharing User Interface Code Between OS X and iOS

  • May 2013
  • By Dileepa Jayathilake (99X Technology)
  • A presentation from the ninth annual SATURN conference, held in Minneapolis, MN, April 29 - May 3, 2013.
  • Publisher: Software Engineering Institute
  • This presentation was created for a conference series or symposium and does not necessarily reflect the positions and views of the Software Engineering Institute.
  • Abstract

    This work describes a solution to a costly problem that surfaces in software product engineering on the Objective C technology stack. Particularly, it emerges when designing a software product targeting both OS X and iOS where a significant part of the functionality is common for both platforms. This raises the question of how much code can be reused between the two implementations.

    Architects will need to probe myriad concerns, and the solution can easily fall victim to combinatorial explosion. Analysis in terms of design patterns can put things in perspective. Both Cocoa and Cocoa Touch (standard frameworks for application development in OS X and iOS, respectively) highly encourage embracing model-view-controller (MVC) as a design pattern. It is even necessary for using certain parts of the two frameworks. Therefore, it is wise to keep our solution inside the MVC design paradigm.

    Yet strict adherence to traditional MVC hinders the architect from harnessing the power of reusing user interface semantics between OS X and iOS. Furthermore, Cocoa and Cocoa Touch differ in terms of the degree of support for implementing the observer pattern between models and views. Thus, the solution space for implementing generic user interface logic must stay outside of framework-provided and hence platform-specific view and controller base classes. However, user interface logic does not naturally fit inside models in MVC either. A diligent analysis makes clear that the need here is a cluster of classes where each one stands as an abstraction of a particular view. This relates closely to the idea of view models in the model-view-view model (MVVM) design pattern that is popular in Windows application development. In the MVVM paradigm, a view model is a container for data that are shown and manipulated in a view along with behavioral logic that rules user interaction with the view. A view model is not supposed to know about specific view instances while it is the view that hooks into the view model.

    As a means of encapsulating generic user interface logic, we experimented with implementing view models to supplement the MVC design. Our architecture comprised models, views, controllers, and view models. This scheme enables developers to implement common user interface logic in view models that are shared between two implementations. In addition to the key benefit of improved code reuse, it delivers other advantages, including enhanced readability, maintainability, and testability.

    View models generally sound alien to the Objective C world. However, our experimentation with this design yielded clear evidence that view models, once employed in combination with MVC in architectures for products targeting both OS X and iOS, carry enormous potential to boost code reuse in addition to several other advantages. We tested it in a product developed for both Mac and iPad and believe that it will serve as a generic design pattern for similar cases.



    Architects will need to probe myriad concerns, and the solution can easily fall victim to combinatorial explosion. Analysis in terms of design patterns can put things in perspective. Both Cocoa and Cocoa Touch (standard frameworks for application development in OS X and iOS, respectively) highly encourage embracing model-view-controller (MVC) as a design pattern. It is even necessary for using certain parts of the two frameworks. Therefore, it is wise to keep our solution inside the MVC design paradigm.

    Yet strict adherence to traditional MVC hinders the architect from harnessing the power of reusing user interface semantics between OS X and iOS. Furthermore, Cocoa and Cocoa Touch differ in terms of the degree of support for implementing the observer pattern between models and views. Thus, the solution space for implementing generic user interface logic must stay outside of framework-provided and hence platform-specific view and controller base classes. However, user interface logic does not naturally fit inside models in MVC either. A diligent analysis makes clear that the need here is a cluster of classes where each one stands as an abstraction of a particular view. This relates closely to the idea of view models in the model-view-view model (MVVM) design pattern that is popular in Windows application development. In the MVVM paradigm, a view model is a container for data that are shown and manipulated in a view along with behavioral logic that rules user interaction with the view. A view model is not supposed to know about specific view instances while it is the view that hooks into the view model.

    As a means of encapsulating generic user interface logic, we experimented with implementing view models to supplement the MVC design. Our architecture comprised models, views, controllers, and view models. This scheme enables developers to implement common user interface logic in view models that are shared between two implementations. In addition to the key benefit of improved code reuse, it delivers other advantages, including enhanced readability, maintainability, and testability.

    View models generally sound alien to the Objective C world. However, our experimentation with this design yielded clear evidence that view models, once employed in combination with MVC in architectures for products targeting both OS X and iOS, carry enormous potential to boost code reuse in addition to several other advantages. We tested it in a product developed for both Mac and iPad and believe that it will serve as a generic design pattern for similar cases.

     

  • Download