Skip to content

How to build a framework

Muriele Trentini edited this page Jan 31, 2018 · 11 revisions

Java Framework Design

Notes

Framework Structure

  • frozen spot to denote a common (or shared) aspect of the family
  • hot spot to denote a variable aspect of the family
  • frozen spots
    • set of abstract and concrete base classes that collaborate in some structure
    • common behaviour
      • implemented by a fixed, concrete template method in a baseclass
  • hot spots
    • represented by a group of abstract hook methods
    • template method calls a hook method to invoke a function that is specific to one family member
    • hot spot is realized in a framework as a hot spot subsystem
      • consists of an abstract base class, concrete subclasses of that base class, and perhaps other related classes
  • two principles for framework construction
    • unification principle
      • inheritance to implement hot spot subsystem
      • template methods and hook methods in same abstract base class.
      • hook methods are implemented in subclasses of the base class.
    • separation principle
      • delegation to implement hot spot subsystem
      • template methods in concrete context class
      • hook methods in separate abstract class and implemented in its subclasses
  • useful patterns
    • Template Method
      • uses unification principle
    • Strategy pattern
      • uses separation principle
  • which principle to choose
    • An application of a framework that uses the separation principle may execute slightly less efficiently than a unification-based framework, but separation may enable the application to adapt itself at runtime by merely changing object references
  • inversion of control
    • its template methods “call down” to the client-supplied hook methods

Roles

During framework-based application development, users fall into four categories or roles:

  • framework developer
    • build framework 'backbone'
  • component developer
    • builds new components and integrates them in the framework
  • application developer
    • assembles components into a custom application
  • end user
    • uses the application

Rules of Thumb

  • control visibility to keep published parts of the Framework small
  • use Interfaces
  • provide well-divined "hook points" that permit extensibility in places where you intend it to occur
  • prevent extension in all other places
Clone this wiki locally