Thursday, February 13, 2014

Software Design Patterns - MBS Pattern (ActionScript)

MBSPattern is a framework that provides an intuitive way to use design patterns.
  • At the application level, MBS is an MVC implementation with an approach to match with MBS naming conventions of the Mind, Body, Soul triad (Soul -> Mind -> Body => Source -> Connection -> Result).
  • MBSPattern is a collection of design patterns with their generic definitions.
  • MBSPattern uses naming conventions that are based on design patterns. That provides a consistent terminology to develop across the technologies.
  • It provides a cosistent way to harness the inherent capabilities of the languages.
MBS broadly categorizes design patterns into three types.
MBS at the core level:
Mind: Behaviour (Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor)
Body: Structure (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy)
Soul: Creation (Abstract Factory, Builder, Factory, Prototype, Singleton)
MBS aims to develop a convenient way to getting started with development using design patterns. It provides a collection of design patterns to use in projects that should be easy to understand and use.
MBS – basic structure at the core level:
MBS categories the design patterns into three parts. There is also a fourth part that puts mind, body and soul into action. Name of the package is action.
MBSPattern code resides in com.shivolve.mbs package. Core design patterns exist in three packages mind body and soul . There is a fourth action package to utilize the in-built features of the language.
  • com.shivolve.mbs.as3.mind contains behavioral patterns. Use these patterns to think and guide behaviour.
  • com.shivolve.mbs.as3.body contains structural patterns. Use these patterns to make thigns with form and structure.
  • com.shivolve.mbs.as3.soul contains creational patterns. Use these patterns to inspire creativity.
  • com.shivolve.mbs.as3.action contains classes that utilize the inheret capabilities of the language. Extend or use the in-build language specific classes in this package.
MBSActionScript
MBSNotificationEvent
MBSNotifierEventDispatcher
MBS categorizes design patterns in three parts - form (body), source (soul) and behaviour (mind). Each Soul can have multiple bodies. Its the base of the application.
Each body has at least one mind.
MBS – basic structure at the applicatin level: MBS corresponds to MVC at the application level.
  • Mind:
    • Control (Strategy, Command)
    • Handles application logic, user interaction and updates Model
    • Has reference of the Soul
  • Body:
    • View (Observer, Context)
    • Handles display / communication
    • User interface with current application state
    • Has a reference of Mind (Control) and Soul (Model)
  • Soul:
    • Model (Subject)
    • Handles data storage and maintains application states
    • Does not have any reference of Mind (Control) or Body (View)
MBS vs MVC:
  • MBS, much like MVC, categorises things in three parts - mind (controller), body (view), soul (model).
  • MBS, unlike MVC, recognizes these three divisions of mind, body and soul in all the areas. For example, a component of body can also have its own mind, body and soul.
MVC design pattern can be refactored into MBS as below.
  • Mind -> ControlMind (controller) coordinates between body (view) and soul (model).
  • Body -> ViewBody (view) is visible to all and some parts of the body (view) can be a window to the soul (model).
  • Soul -> ModelFor a general understanding, as we know from our general knowledge Soul (Model) is something we refer to. Soul (model) does not refer to us (view or control) for its business.
One of the many ways design patterns can be used at the application level:
Observer Pattern: SOUL is SUBJECT and BODY is OBSERVER.
Strategy Pattern: BODY is CONTEXT and MIND is STRATEGY.
Composite Pattern: BODY contains Components and COMPOSITE nodes.
Responsibilities:
Mind handles user input and changes the state of the application in the Soul
Body contains user interface and displayes the state of the application
Soul contains application data and logic to manage the state of the application
Benefits:
  • Provides a way to use the inherent language capabilities right at the root of the framework (com.shivolve.as3.mbs.action ).
  • Provides a clear separation between technology specific details from pure design pattern related, independent of technology, details.
    • com.shivolve.as3.mbs.action package contains the code to utilize the inherent capabilities of the Action Script 3 language.
    • com.shivolve.as3.mbs.mind com.shivolve.as3.mbs.body andcom.shivolve.as3.mbs.soul packages contain the design pattern definitions.
  • Uses generic terminology (like Mind, Body and Soul) that everybody can understand and it becomes easy to get started.
Implementation Details:
  1. User interacts with an application body part. For example clicks a button in the body.
  2. The Body sends the click event to the Mind to handle it.
  3. The Mind updates the Soul based on its own decision to handle the button click.
  4. The Soul updates itself and tells the Body that the state of the soul has now changed.
  5. The Body observes the state information from the Soul and updates itself.
OOPs:
Use Inheritance to cut down on redundancy of methods doing same thigs.
Use Abstraction by implementing the solution independent of the details. Add the details just when they are required.
Use Encapsulation to build the application as combination of modules and components.
Use Encapsulation by using getters and setters. Use private variables for the details you want to hide.
Use Polymorphism to implement abstract methods in multiple sub-classes. Polymorphism allows you to avoid using switch or if statements.

Interface vs. Abstract classes

Use abstract classes for the ability to add more behaviors easily. Use interfaces to avoid base class if there not anything other classes should inherit.
Philosophy:
Object oriented programming models the real world. MBS programming uses mind, body, soul concepts to model the real world.
MBSPattern, at the core, is a collection of design patterns categorized as mind, body or soul. This is an attempt to feel at home by using Mind, Body, Soul perspective. Mind, Body and Soul form the universal triad. This being so evolutionary does not force to live to constraints to new definitions every time.
  • Thinking of Control, View, Model as Mind, Body and Soul feels great.
  • Application souls, minds and bodies extend the MBS Soul, Mind and Body.
    (All the souls extend the One Higher Soul. All the Bodies are an extension of His Body. Only That Mind works in all the minds.)
  • Classes within the mbs.action package extend the language specific built-in classes to utilize the inherent capabilities of the language (Action Script 3 in case of MBS_AS3).
MBS vs MVC:
  • Mind vs Control -> Mind understands. To understand is the best way to control. Mind refers to soul. Directs the body.
  • Body vs View -> Body has a form. It can be seen and heard. Body is there to see, touch, hear and feel.
  • Soul vs Model -> Soul is the best model to refer to. Soul is independent, inherent, omnipresent. Mind and Body can not ignore Soul.
You should find it useful in the long run and also if you have to change from one technology to other. Mind, Body, Soul relate more to life and our thinking patterns from any walk of life.

No comments: