Behavioral patterns in data

From Simulace.info
Revision as of 15:10, 22 January 2017 by Hanka (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Essay topic: Behavioral patterns in data

Class: 4IT496 System Simulation (WS 2016/2017)

Author: Bc. Hana Nápravníková


Introduction:

In software engineering, a software design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Design patterns may be viewed as a structured approach to computer programming intermediate between the levels of a programming paradigm and a concrete algorithm and they were originally grouped into the categories: creational patterns, structural patterns and behavioural patterns and described using the concepts of delegation, aggregation and consultation.


Behavioral patterns in general:

Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects. Behavioral patterns describe not just patterns of objects or classes but also the patterns of communication between them. These patterns characterize complex control flow that’s difficult to follow at run-time. They shift focus away from flow of control to let you concentrate just on the way objects are interconnected.

Behavioral patterns.png

Behavioral patterns used for data Structures Implementation

Long gone are the days when it was sufficient to deliver to all users the same content or experience. These days, customer experience optimization must be personalized.

alt text

alt text

Interator

This design pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. The classes or objects participating in this pattern are:

       •	Iterator – defines an interface for accessing and traversing elements
       •	Concreteiterator – implements the Iterator interface; keeps track of the current position in the traversal of the aggregate
       •	Aggregate – defines an interface for creating an Iterator object
       •	ConcreteAggregate – implements the Iterator creation interface to return an instance of the proper Concreteiterator.
Iterator.gif

The Iterator design pattern is maybe the first design pattern that has been used for data structures. Its advantages are so important such that probably now there is no data structures library that does not use it. The key idea in this pattern is to take the responsibility for access and traversal out of the container object and put it into an iterator object. An iterator is consider to be robust if ensures that insertions and removals do not interfere with traversal, and it does it without copying the container.


Template Method

Template method design pattern defines the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure. The classes and objects participating in this pattern are:

      •	AbstractClass – defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defines in abstractclass or those of other objects. 
      •	ConcreteClass – implements the primitive operations to carry out subclass-specific steps of the algorithm. 
Templete method.jpg

The interesting example of using Template Method pattern is related to the implementation of different sorting methods, based on Merrit taxonomy. At the top of her sorting taxonomy is an abstract divide-and-conquer algorithm: split the array to be sorted into two subarrays, sort the subarrays, and join the sorted subarrays to from a sorted array. Sorting could be modelled as an abstract class with a template method to perform the sorting. This method delegates the splitting and joining of arrays to the concrete subclasses, which use an abstract ordering strategy to perform comparisons on objects.


Strategy

Strategy design pattern defines a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. A good example is represented by the binary tree traversals. We may have preorder, inorder and postorder traversal for binary trees. In this way we may dynamically choose the traversal order for a binary tree. Encapsulating the algorithm in separate Strategy classes lets us vary the algorithm independently of its context, making it easier to switch and understand.

Strategy.png


Summary

Using patterns in data structures implementation represents a step forward in this field. Patterns allow data structures to be implemented in a very general and flexible way. There have been presented some examples of data structures that use the advantages: Iterator, Templet Method and Strategy. Behavioral patterns deal with encapsulating algorithms and managing or delegating responsibility among objects. They focus more on communication and interaction, dynamic interfaces, object composition and object dependency.


Resources

Behavioral Patterns [online]. USA: Addison-Wesley, 1994 [cit. 2017-01-21]. Dostupné z: http://www.cs.unc.edu/~stotts/GOF/hires/chap5fso.htm

Access our library of analytics eBooks - for free Understand User Behavioral Patterns with Web Analytics Data [online]. Data Informed: Efrat Ravid, 2015 [cit. 2017-01-21]. Dostupné z: http://data-informed.com/22124-2/

Behavioral Design Patterns Used in Data Structures Implementation [online]. Niculescu Virginia Department of Computer Science: Babe¸s-Bolyai University, 2005 [cit. 2017-01-22]. Dostupné z: https://www.cs.ubbcluj.ro/~vniculescu/didactic/SD_DID/behavioralDesignPatterns.pdf