Design Pattern: A Template For A Design That Solves A Programming Problem

Páginas: 9 (2027 palabras) Publicado: 16 de noviembre de 2012
A design pattern is a tool of abstraction used in object-oriented software development as well as other fields. It is a template for a design that solves a general, recurring problem in a particular context. A design pattern is thus a kind of guide for a particular, concrete design: an “instantiation” of a pattern, in a sense. There is some flexibility in how you can apply a design pattern, andoften things such as the programming language and existing architectures can determine how the pattern is applied.

Several themes or principles of design influence design patterns. These design principles are rules of thumb for constructing object-oriented systems, such as “encapsulate the aspects of system structure that vary” and “program to an interface, not an implementation.” They expressimportant insights. For example, the principle of encapsulation says that if you isolate the parts of a system that vary, and encapsulate them, they can vary independently of other parts of the system, especially if you define interfaces for them that are not tied to implementation specifics. You can later alter or extend those variable parts without affecting the other parts of the system. Youthus eliminate dependencies and reduce couplings between parts, and consequently the system becomes more flexible and easier to change.

Benefits such as these make design patterns an important consideration when you’re writing software. If you find, adapt, and use patterns in your app’s design, that program—and the objects and classes that it comprises—will be more reusable, more extensible, andeasier to change when future requirements demand it. Moreover, apps that are based on design patterns are generally more elegant and efficient than apps that aren’t, because they require fewer lines of code to accomplish the same goal.

You can find adaptations of design patterns throughout the Cocoa Touch and Cocoa frameworks and in the Objective-C runtime and language. Some of thesepattern-based mechanisms you get almost “for free,” but others require some work on your part. And you can apply design patterns to your own app’s code when the situation warrants it. If you use the same patterns that the Cocoa Touch and Cocoa frameworks use, your code tends to fit in better with the frameworks’ code and work more elegantly.

The Most Important Design Pattern: Model-View-Controller

TheModel-View-Controller design pattern (commonly known as MVC) assigns objects in an app one of three roles: model, view, or controller. The pattern defines not only the roles objects play in the app, it defines the way objects communicate with each other. Each of the three types of objects is separated from the others by abstract boundaries and communicates with objects of the other types acrossthose boundaries. The collection of objects of a certain MVC type in an app is sometimes referred to as a layer—for example, a model layer.


MVC is central to a good design for any iOS app or Mac app. The benefits of adopting this pattern are numerous. Many objects in these apps tend to be more reusable, and their interfaces tend to be better defined. Apps having an MVC design are also moreeasily extensible than other apps. Moreover, many technologies and architectures that your app can use are based on MVC and require that your custom objects play one of the MVC roles.

You might not be aware of it, but you have already created an app that is based on MVC: HelloWorld in Your First iOS App. The model object is the userName property (an NSString object) declared and managed by theHelloWorldViewController class. Instances of the HelloWorldViewController and HelloWorldAppDelegate classes are the app’s controller objects, and the view objects of the app are the text field, label, button, and the background view.

Complete information about Model-View-Controller is in “Model-View-Controller” in Concepts in Objective-C Programming.

Model Object

A model object encapsulates...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Design for emotional experience
  • design for x factor
  • Colour design for better classrooms
  • ENSAYO SOBRE Design for logistic
  • Designer
  • designer
  • Design
  • Design

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS