1.1. What's in a Modeling Language?A modeling language can be made up of pseudo-code, actual code, pictures, diagrams, or long passages of description; in fact, it's pretty much anything that helps you describe your system. The elements that make up a modeling language are called its notation . Figure 1-1 shows an example of a piece of UML notation. Figure 1-1. A class declaration as it can be shown using UML notation
However, notation is not the whole story. Without being told that one of the boxes in Figure 1-1 represents a class, you wouldn't necessarily know what it is, even though you might be able to guess. The descriptions of what the notation means are called the semantics of the language and are captured in a language's meta-model. A modeling language can be anything that contains a notation (a way of expressing the model) and a description of what that notation means (a meta-model). But why should you consider using UML when there are so many different ways of modeling, including many you could make up on your own? Every approach to modeling has different advantages and disadvantages, but UML has six main advantages:
1.1.1. Detail Overload: Modeling with CodeSoftware code is an example of a potential modeling language where none of the detail has been abstracted away. Every line of code is the detail of how your software is intended to work. Example 1-1 shows a very simple class in Java, yet there are many details in this declaration. Example 1-1. Even in a simple Java class, there can be a lot of detail to navigate through
Example 1-1 shows all of the information about the Guitar class, including inheritance relationships to other classes, member variables involving other classes, and even implementation details for the methods themselves. What's wrong with using software source code as your model? All of the details are there, every element of the language's notation has meaning to the compiler, and with some effective code-level comments, such as JavaDoc, you have an accurate representation of your software system, don't you? The truth is that you haven't actually modeled anything other than the software implementation. The source code focuses only on the software itself and ignores the rest of the system. Even though the code is a complete and (generally) unambiguous definition of what the software will do, the source code alone simply cannot tell you how the software is to be used and by whom, nor how it is to be deployed; the bigger picture is missing entirely if all you have is the source code. As well as ignoring the bigger picture of your system, software code presents a problem in that you need to use other techniques to explain your system to other people. You have to understand code to read code, but source code is the language for software developers and is not for other stakeholders, such as customers and system designers. Those people will want to focus just on requirements or perhaps see how the components of your system work together to fulfill those requirements. Because source code is buried in the details of how the software works, it cannot provide the higher level abstract views of your system that are suitable for these types of stakeholders. Now imagine that you have implemented your system using a variety of software languages. The problem just gets worse. It is simply impractical to ask all the stakeholders in your system to learn each of these implementation languages before they can understand your system. Finally, if your design is modeled as code, you also lose out when it comes to reuse because design is often reusable whereas code may not be. For example, reimplementing a Java Swing application in HTML or .NET is much simpler if the design is modeled rather than reverse engineering the code. (Reverse engineering is extracting the design of a system from its implementation.) All of these problems boil down to the fact that source code provides only one level of abstraction: the software implementation level. Unfortunately, this root problem makes software source code a poor modeling language. 1.1.2. Verbosity, Ambiguity, Confusion: Modeling with Informal LanguagesAt the opposite end of the spectrum from complete and precise source code models are informal languages. Informal languages do not have a formally defined notation; there are no hard and fast rules as to what a particular notation can mean, although sometimes there are guidelines. A good example of an informal language is natural language. Natural languagethe language that you're reading in this bookis notoriously ambiguous in its meaning. To accurately express something so that everyone understands what you are saying is at best a challenge and at worst flat-out impossible. Natural language is flexible and verbose, which happens to be great for conversation but is a real problem when it comes to systems modeling. The following is a slightly exaggerated but technically accurate natural language model of Example 1-1:
If you take a hard look at this definition, you can see problems everywhere, almost all resulting from ambiguity in the language. This ambiguity tends to result in the, "No, that's not what I meant!" syndrome, where you've described something as clearly as possible, but the person that you are conveying the design to has misunderstood your meaning (see Figure 1-2). Figure 1-2. Even a simple natural language sentence can be interpreted differently by different stakeholders in the systemThe problems with informal languages are by no means restricted to written languages. The same description of Guitarist might be presented as a picture like that shown in Figure 1-3. Figure 1-3. Informal notation can be confusing; even though my intentions with this diagram might appear obvious, you really can't be sure unless I also tell you what the notation meansFigure 1-3 is another example of an informal language, and it happens to be a notation that I just made up. It makes perfect sense to me, but you could easily misinterpret my intentions. As with the natural language model, all of the details are present in Figure 1-3's picture, but without a definition of what the boxes, connections, and labels mean, you can't be sure about your interpretation (or mine!).
The basic problem with informal languages is that they don't have exact rules for their notation. In the natural language example, the meanings of the model's sentences were obscured by the ambiguity and verbosity of the English language. The picture in Figure 1-3 may not have suffered from quite the same verbosity problems, but without knowing what the boxes and lines represent, the meaning of the model was left largely to guesswork. Because informal languages are not precise, they can't be transformed into code as a formal language can. Imagine if Figure 1-3 had a set of formal rules; then you could generate code that implemented the classes for Guitarist, Person, and so on. But this is impossible without understanding the rules. Unfortunately, informal languages will always suffer from the dual problem of verbosity and ambiguity, and this is why they are a poorand sometimes extremely dangeroustechnique for modeling systems, as shown in Figure 1-4. Figure 1-4. With an informal notation, the problem of confusion through ambiguity still exists
1.1.3. Getting the Balance Right: Formal LanguagesYou've now seen some of the pitfalls of using a too-detailed language for modeling (source code) and a too-verbose and ambiguous language for modeling (natural language). To effectively model a systemavoiding verbosity, confusion, ambiguity, and unnecessary detailsyou need a formal modeling language . Ideally, a formal modeling language has a simple notation whose meaning is well-defined. The modeling language's notation should be small enough to be learned easily and must have an unambiguous definition of the notation's meaning. UML is just such a formal modeling language. Figure 1-5 shows how the code structure in Example 1-1 can be expressed in UML. For now, don't worry too much about the notation or its meaning; at this point, the UML diagram is meant to be used only as a comparison to the informal pictorial and natural language models shown previously. Figure 1-5. Expressing the static structure of the Guitarist class structure in formal UML notationEven if you don't yet understand all of the notation used in Figure 1-5, you can probably start to grasp that there are some details present in the codesee Example 1-1that are not modeled here. For example, the specific implementation of the play( ) method has been abstracted away, allowing you to visualize the code's structure without excess clutter. The best thing about having modeled the system using UML is that the notation in Figure 1-5 has a specific and defined meaning. If you were to take this diagram to any other stakeholder in your system, provided he knows UML, the design would be clearly understood. This is the advantage of using formal languages for modeling as shown in Figure 1-6. Figure 1-6. With a modeling language that has a formally defined meaning, you can ensure that everyone is reading the picture the same way |