F RED Practical Viewpoint. Content  Basic concepts  Creating a framework with Fred  Using a framework with Fred

  • Published on
    21-Jan-2016

  • View
    217

  • Download
    0

Embed Size (px)

Transcript

  • FREDPractical Viewpoint

  • ContentBasic conceptsCreating a framework with FredUsing a framework with Fred

  • Basic Concepts 1/3Both frameworks and applications are software architectures.Structural elements of an architecture, such as patterns, data types, methods and fields are called structures.A structure can be a template defining a set of possible implementations.

  • Templates are used to instantiate new structures. A template is called a model in relation to its instance. We can also say that an instance is based on a template. A structure can have multiple models.modelinstanceSomeFrameworkSomePatternSomeClassAnotherApplicationAnotherPatternAnotherClassYetAnotherClassmodelmodelinstanceinstanceBasic Concepts 2/3

  • By default each structure is an instance of a corresponding meta-structure.Basic Concepts 3/3

  • How to create a framework with Fred?How to use the created Framework with Fred?A Brief ExampleTo answer these questions we will use a framework called List Box Framelet as an example. The framelet is also discussed in the paper Pattern-Oriented Framework Engineering Using Fred [HHT98]. The original framelet was presented by Pree and Koskimies [PrK98].

  • The Framelet

  • New structures, e.g. fields and methods, can be created directly in the advanced source code editor.Some structures can be defined to be generated automatically, e.g. getters and setters for fields.Pattern selection can be simplified using the Pattern Selection Wizard.

  • GHJ95Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns - Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.HHT98Hakala M., Hautamki J., Tuomi J., Viljamaa A., Viljamaa J: Pattern - Oriented Framework Engineering Using FRED. Manuscript, submitted for publication, 1998.PrK98Pree W., Koskimies K.: Framelets - Small and Loosely Coupled Frameworks. Manuscript, submitted for publication, 1998.

    Many graphical applications provide list boxes together with buttons to add items to a list box, and to modify and remove them. Typically a separate dialog is used to add and modify items. The associated programming task can be packed into a small self-contained framework, called List Box Framelet.List Box Framelet provides:A view to show and maintain a list of items.Data transformation between the items and their associated displays.Class definitions for the items.Class definitions for the item displays.Application developer provides:*In the List Box Framelet example we will need some general patterns. These patterns are located in Pattern Catalog. To demonstrate the catalog it has been opened with the Designer tool in the above figure. Currently the catalog has pattern structures to represent Abstract Factory, Singleton, and Bean Composition patterns. Abstract Factory and Singleton are discussed by Gamma et al. [GHJ95]. The Bean Composition pattern is developed by FRED development team; it is a simple pattern to create UI components.Each structure in the catalog is a template; they can be used to instantiate new structures in other architectures. To separate template and non-template structures the Designer tool uses blue images for templates and light-gray images for non-templates. It is easy to change a structure to template and vice versa.The Designer tool has the following parts:Hierarchy panel contains views to show relations between structures.Desktop for source code editors, composition tools, etc.Notes panel for messages and documentation.In the figure the Structure view has been selected in the Hierarchy panel. The Structure view shows classes and interfaces categorized by the patterns. Other views are, e.g., the Inheritance view which shows the traditional class hierarchy.Situation in the figure:The developer has created a new architecture called ListBoxFramelet. It has been made an instance of PatternCatalog.ListBoxFramelet has been selected in the Structure view; the Models list shows the models (PatternCatalog) of the selected structure. If the model has templates they are shown under the model (SingletonPattern, AbstractFactoryPattern, BeanCompositionPattern). With the templates the developer can instantiate new structures.ListBoxFramelet is an instance of MetaArchitecture, too. However, this model is not shown in the Models list. For convenience Fred has short-cut menu commands to simplify the use of meta structures. By default each architecture has the OtherClasses pattern; it is used to store miscellaneous classes and interfaces that are not involved in any other pattern.

    Situation in the figure:The OtherClasses pattern has been selected in the Structure view.OtherClasses is an instance of MetaPattern which has the MetaType template. This template can be used to create arbitrary classes and interfaces.OtherClasses is not based on any other pattern and for convenience meta structures are not shown in the Models list.The developer has opened a popup menu for OtherClasses. The New Substructure menu command is a short-cut to create a class or an interface as an instance of MetaType.Situation in the figure:The FieldAccessor and Item interfaces and the Display class have been created under OtherClasses. They are based on MetaType.The developer has selected Display and opened the popup menu for it to create new substructures (methods and fields). The created methods and fields are instances of MetaMethod and MetaField, respectively.In the Desktop the developer has opened source code editors for Item and Display.Situation in the figure:To make the framelet code more organized the developer has created a new pattern called ItemPattern. It has been created by selecting ListBoxFramelet and by using the New Substructure command. Hence, the ItemPattern is an instance of MetaPattern.The developer has moved FieldAccessor, Item, and Display from OtherClasses to ItemPattern.The developer has selected ListBoxFramelet, so that PatternCatalog and its templates are shown in the Models list (recall that ListBoxFramelet is based on PatternCatalog).The developer has selected the AbstractFactoryPattern template in the Models list and prepares to use the Associate to Instance menu command.A list of available patterns will open and the developer will select ItemPattern to be an instance of AbstractFactoryPattern.At this point the developer notices that ItemPattern looks familiar. Then she realizes that AbstractFactoryPattern [GHJ95] could naturally be used here; obviously the Item interface and its createDisplay method correspond to the AbstractFactory template and its createProduct method. The Display class in turn corresponds to AbstractProduct.

    To take full advantage of AbstractFactoryPattern, the developer associates ItemPattern with it:Situation in the figure:The developer has selected ItemPattern. Because the pattern is now based on AbstractFactoryPattern, appropriate templates are shown in the Models list.The AbstractFactory template has been selected in the Models list. The developer prepares to associate the Item class to be an instance of AbstractFactory.Situation in the figure:The Item interface is now an instance of AbstractFactory.The developer has selected the createProduct template in the Models list and prepares to associate the createDisplay method to be based on it.The Display class will be associated with the AbstractProduct template similarly.Now Item is an instance of AbstractFactory and Display is an instance of AbstractProduct. The developer notes that AbstractFactoryPattern has also templates for ConcreteFactory and ConcreteProduct. It seems that they must be satisfied by the application developer. To make this possible, the developer must create some templates, too.Situation in the figure:The developer has created a new class called UserItem as an instance of ConcreteFactory. The developer has changed UserItem to be a template. This means that the methods and fields of UserItem are also templates. Further, ItemPattern and ListBoxFramelet turn into templates.Because UserItem is now a template, the application developer can use it to create application specific item classes.To create a template for user displays, the developer has selected the ConcreteProduct template in the Models list. By using the Create New Instance menu command the developer will create a new class template called UserDisplay.Situation in the figure:The developer has finished the UserItem and UserDisplay templates.Patterns called TransformerPattern and UserInterface have been created.TransformerPattern is an instance of SingletonPattern and it contains the Transformer class to handle data transfer between items and displays.UserInterface is an instance of BeanComposition and it contains various UI classes and components like buttons and panels.Situation in the figure:The application developer has created the ContactManager architecture based on ListBoxFramelet.ContactManager is selected in the Structure view. The ListBoxFramelet model and its template are shown in the Models list.The ItemPattern template has been selected and the application developer prepares to create a new instance for it.Let us suppose that an application developer is making a simple application to maintain contact informations. She decides to use the List Box Framelet framework to make a simple user interface for the application.Situation in the figure:The application developer has created the ContactPattern pattern as an instance of ItemPattern.In the Models list there are the templates UserItem and UserDisplay. This means that the application developer must provide classes based on these templates.Situation in the figure:The application developer has created the Contact class as an instance of UserItem and the ContactDisplay class as an instance of UserDisplay.ContactDisplay has been selected in the Structure view. In the Models list the application developer has selected the getVal template. Some template specific documentation is shown in the Notes panel.The same structure can be involved in multiple patterns:The application developer has created the UserInterface pattern based on BeanComposition.The BeanComposition pattern has a template called Composition. This template represents a class containing UI components. Because the created ContactDisplay class is obviously an UI class, it is sensible to associate ContactDispay to be an instance of Composition.In the Models list one can see the models of ContactDisplay (UserDisplay, Composition) and their templates. The name of the Composition model is drawn darker because ContactDisplay was selected under UserInterface in the Structure view.Situation in the figure:To test ContactManager the application developer has created the TestDriver class with the main method under the OtherClasses pattern.A source code editor has been opened for the TestDriver class.