Design Patterns Tutorial
A tutorial on GOF design patterns. This tutorial is for beginners who are going to learn design patterns for the first time. Each pattern is expalined with suitable examples.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Introduction. No Comments on Design Patterns in Smalltalk MVC

In this article we will learn about design patterns in Smalltalk MVC. The patterns described are observer, composite and strategy patterns.

 

The Model/View/Controller set of classes are used to build user interfaces in Smalltalk-80. MVC consists of three kinds of objects.

 

Model is the application object. View is the representation of the model and the Controller specifies how the user interface (View) reacts to the user input. Before MVC, these three objects (Model, View and Controller) used to be coupled together.

 

design patterns in smalltalk

 

MVC decouples model and view objects using the subscribe/notify protocol. Whenever the data in the model changes, it has to notify the associated views. In response, each view gets a chance to update itself.

 

This allows add or create views on a model without changing the model itself. In the figure we can see three views: a table display, a bar chart and a pie chart associated with the same model. When the data in the model changes, the views are updated accordingly.

 

This design that decouples views from models can be applied in a more general problem context like: decoupling objects where a change in one object causes change in all other associated objects. Such design pattern is the observer pattern.

 

Another feature of MVC is, views can be nested. For example, a control panel can contain a set of buttons as a button view along with other controls which are nested inside the main container view.

 

In Smalltalk, nested views are supported by the class CompositeView which is a sub class of the View class. This design can be applied in a more general context like: to group a set of objects and that group can be treated as an individual object. This general design is described as the composite pattern.

 

MVC also lets us change how the view responds based on the user input. This is achieved through controller classes in Smalltalk. For example, we might want the view to respond based on key strokes or through mouse movement on the user interface.

 

It is even possible to change a view’s controller at run time. This design can be applied in a general context: where you have several variants of an algorithm and you want to apply a single algorithm either statically or dynamically. This View-Controller relationship is an example of Strategy pattern. A strategy is an object which represents an algorithm.

 

These three patterns: Observer, Composite and Strategy specify the main relationships in MVC although there are other design patterns like Factory Method and Decorator.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Drag To Verify