Rosa's Breakfast Service
The example we will be exploring in this book is the ordering system for Rosa's Breakfast Service. The example system described in this and subsequent chapters is implemented using the OptimalJ tool. You can download OptimalJ and the example at the Web site http://www.klasse.nl/mdaexplained.
4.1.1 The Business
Rosa has founded a company that supplies a complete breakfast delivered to the homes of its customers. Customers can order from one of the breakfast menus on Rosa's Web site, indicate the hour and place of delivery, give their credit card number, and the ordered breakfast will be delivered. Rosa's slogan is: "Surprise your husband, wife, lover, valentine, mother, father, or friend on their special day while still enjoying the comfort of your bed."
Rosa has composed a series of breakfasts, each of which comes with special decorations. For instance, the Valentine breakfast is served on plates decorated with small hearts and cupids, with matching napkins. The items served are set by the choice of breakfast. For instance, if you choose the French breakfast, you will get one cup of coffee, one glass of orange juice, two croissants and one roll, butter, and jam. But if you choose the English breakfast, you will get two fried eggs and bacon, three pieces of toast, marmalade, and a pot of tea. The Champagne Feast breakfast, which always serves two persons, includes a bottle of champagne, four baguettes, a choice of french cheese and pâtés, and a thermos bottle filled with coffee (to sober up afterwards). Orders can be filled for any number of people, where any in the party may order a different breakfast.
The items served are set, but customers can indicate the style in which the breakfast is served. They can choose between simple, grand, and deluxe. A simple breakfast is served on a plastic tray with carton plates and paper napkins. The orange juice glass, when included, is made of plastic, too. A grand breakfast is served on a wooden tray with pottery plates and cups, and simple white cotton napkins, and the glass is made of real glass. A deluxe breakfast is served on a silver tray with a small vase with some flowers. The plates are fine pottery plates and the napkins are decorated, made from the finest linen. Obviously, the price of the breakfast is higher when the serving style is better. Some breakfast types, like the Champagne Feast, can be ordered in the grand or deluxe style only.
Rosa has ten employees that come in her kitchen at half past five in the morning and work until noon. Five of them take care of deliveries, and five do the cooking and preparation of the breakfasts. Rosa's kitchen is located next to a bakery. The first thing Rosa does in the morning is get fresh bread from the bakery. All other ingredients are kept in supply. Twice a week their inventory is resupplied.
Rosa wants to give her customers a bit of flexibility. Customers may, after choosing a standard breakfast as basis, decide to put in extra comestibles, alter the amount of certain parts, and even remove parts from the breakfast. So, if you like the Champagne Feast breakfast, you may order two bottles of champagne instead of one, add another baguette, and leave out the smelly cheese and the coffee (coffee won't help after two whole bottles of champagne anyhow).
4.1.2 The Software System
In this example we are not very interested in the delicious breakfasts Rosa makes; instead, we look at the system needed to support Rosa's business. The ordering system is a standard Web-based, three-tier application. There will be two different Web interfaces, one for the customers, and one for Rosa's employees to indicate which breakfasts they need to make and deliver. If the customer agrees, his or her name and address will be kept in the system. This will enable Rosa to give a discount to regular customers.
The customer Web interface must respond to the customer information. When a known customer logs in, a list of previous orders must be shown with the option to repeat that order. The database should hold customer information: the name, price, and contents of all breakfast types offered, and the ordering information. The middle-tier will primarily add orders and customers to the database.
We have decided to use a three-tier architecture for Rosa's system. Of course, other choices could be made, and the decision on what architecture to use must be made carefully, but that is not the subject of this book. The three-tier application will consist of a database, a middle tier using Enterprise Java Beans (EJB), and a user interface built with Java Server Pages (JSP).
Applying the MDA Framework
Rosa will be interested only in the final system. But, because this is an example of how the MDA framework can be applied, we are interested in the process of building Rosa's Breakfast System. We will dissect this process into parts that have meaning within the MDA framework. We must identify which PSMs and code models should be delivered and which transformation definitions should be used to generate the PSMs and code models. All elements of the MDA framework used in this example are shown in Figure 4-1. The models are shown as rectangles and the transformations are shown as arrows.
Figure 4-1. Three levels of models for Rosa's Breakfast Service
4.2.1 The PIM and PSMs
To start the MDA process we need to build a platform-independent model that comprises the whole of Rosa's business. For the sake of simplicity, our PIM will be written in plain UML. This is the only model that the developer will create completely "by hand." The other models are mostly generated.
Because each tier is implemented using a different technology, we need three PSMs, one for each tier. The first PSM specifies the database, and is described by a relational model depicted in an Entity-Relationship diagram.
The PSM for the middle tier, which we call the EJB model, is written in a language that is a UML variant. It uses classes, associations, and so on, as in UML, but there are a number of stereotypes defined explicitly for the EJB platform.
The PSM for the Web interface is also written in a UML variant. This language uses different stereotypes than the UML variant used for the EJB model. Neither UML variant is standardized as a profile. They are small and simple, so we will not give an explanation of these UML variants.
4.2.2 The PIM to PSM Transformations
Because three PSMs need to be generated, we need three PIM to PSM transformations:
A PIM to Relational model transformation: a transformation that takes as input a model written in UML and produces a model written in terms of Entity-Relationship diagrams.
A PIM to EJB model transformation: a transformation that takes as input a model written in UML and produces a model written in a UML variant using special EJB stereotypes.
A PIM to Web model transformation: a transformation that takes as input a model written in UML and produces a model written in a UML variant using special stereotypes for the Web interface.
4.2.3 The PSM to Code Model Transformations
For each PSM, we need to generate code. Note that in Chapter 2, The MDA Framework, code was explicitly included to fit in our definition of model. Therefore, we can speak of code models written in some programming language. The code model defines the application in code. For Rosa's business we will have three code models in SQL, Java, and JSP, respectively. Therefore, we need three PSM to code transformations:
A relational model to SQL transformation: a transformation that takes as input a model written as an Entity-Relationship model and produces a model written in SQL.
An EJB model to Java transformation: a transformation that takes as input a model written in the UML EJB variant and produces a model written in Java.
A Web model to JSP and HTML transformation: a transformation that takes as input a model written in the UML Web variant and produces a model written in JSP and HTML.
4.2.4 Three Levels of Abstraction
All models in this example describe or specify the same system, although at a different level of abstraction.
At the highest level of abstraction we define the PIM. This model defines the concepts without any specific technology detail.
At the next level there are the PSMs. These models abstract away from coding patterns in the technologies, but still they are platform specific.
At the lowest level there are the three code models. These models are, of course, pure platform specific models.
Figure 4-1 shows the different models at the three levels of abstraction and the transformations between them. Note that the three tiers and the three levels of abstraction are orthogonal. The levels of abstraction are depicted from top to bottom; the tiers are depicted from right to left.
The following two chapters address the transformations and technologies needed to generate the PSMs and code models. Chapter 5 describes the transformation to the three PSMs and Chapter 6 explains portions of the code models of Rosa's Breakfast Service.
The PIM in Detail
The PIM for Rosa's Breakfast System is depicted in Figure 4-2. The PIM is the only model that must be created by humans in a creative process. To find out how to build such a model you can read a large number of books on UML and modeling. Here we assume that the creative process has been successfully completed with the PIM in Figure 4-2 as the result.
Figure 4-2. PIM of Rosa's Breakfast Service
In the PIM every standard breakfast contains a number of parts; each part indicates the amount in which a certain comestible is present in the breakfast. Every order consists of a number of breakfasts. The price of each breakfast is determined based on the chosen style and the price of the chosen standard breakfast. The price of the order is simply the addition of the prices of all breakfasts plus a small delivery fee.
The model in Figure 4-2 defines the breakfast services independently from any specific technology, so indeed, it is a PIM. But Rosa does not want a model, she wants a running system. Therefore, we need to transform the PIM into a number of PSMs, taking into account the relationships between these PSMs.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment