• Ei tuloksia

Object diagram examples

8.7 An XML example

As an alternative object-level representation to UML diagrams, Listing 8-1 below presents an example of an object system encoded in XML format. The XML listing represents the note example of Figure 8-2 a), and is structurally equivalent to the object diagram in Figure 8-2 b). The XML listing is, however, more detailed in its use of object attributes. In the XML representation, each aggregation relationship is stored as an XML element, with start and end tags named according to class names from the object model.

st2 : Staff

c1 : Clef value = G

t1 : TimeSignature value = 4/4

n2 : Note

s2 : Stem h2 : Notehead t2 : Tie

st1 : Staff

n1 : Note

s1 : Stem h1 : Notehead

t1 : Tie

b1 : Barline

Figure 8-7: Examples of tied notes

a)

b)

The XML example presented below is simplified from a full-featured XML document. In particular, it does not contain a formal definition of the representa-tion in the form of a Document Type Definirepresenta-tion (DTD) (Eckstein 1999: 9-10) or a “DOCTYPE” reference to an external DTD. The XML example is, however, syntactically correct and “well-formed” according to general XML requirements (Eckstein 1999: 14-15).

The listing shows a hierarchical aggregation structure with the Score object sc1 on the top level, System sys1 on the next level, and Staff st1 on the next level. The Staff object, in turn, contains other objects, including StaffLines, Notes, Barlines, and LedgerLines. All objects contain attributes named “origin”

and “size”. They are represented with respectively named XML elements. Both origin and size contain two coordinate values, horizontal and vertical. Origin represents the position of the object within its aggregate’s internal coordinate system. Size, in turn, represents the width and height of the object relative both to the size of the object’s aggregate and to an assumed “default” size.

Some of the objects contain a “value” attribute. For example, in Notehead objects, value represents the type of note head. The SingleBarline object con-tains the attribute “dashed”, which in the example is set to “no”. The dimensions attribute of our analysis model was presented above in the description of the CMNSymbol class. In this case, it is considered to be calculated automatically.

Hence, respective XML elements have not been included in the example listing.

The XML listing is presented here in order to clarify further the structure of the object model. The XML example should be considered as only one of many possible XML implementations of the analysis model.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<Score>

<Page id="pg1">

<Staff id="st1">

<origin>0 0</origin><size>8 70</size>

<StaffLine id="sl1">

<origin>0 0</origin><size>1 1</size>

</StaffLine>

<StaffLine id="sl2">

<origin>2 0</origin><size>1 1</size>

</StaffLine>

<StaffLine id="sl3">

<origin>4 0</origin><size>1 1</size>

</StaffLine>

<StaffLine id="sl4">

<origin>6 0</origin><size>1 1</size>

</StaffLine>

<StaffLine id="sl5">

<origin>8 0</origin><size>1 1</size>

</StaffLine>

<Clef id="c1">

<origin>1.5 2</origin><size>1 1</size>

<value>G</value>

</Clef>

<TimeSignature id="t1">

<origin>8.999 0</origin><size>1 1</size>

<value>3/4</value>

</TimeSignature>

<Note id="n1">

<origin>16.499 -2</origin><size>1 1</size>

<Notehead id="h1">

<origin>0 0</origin><size>1 1</size>

<value>closed</value>

</Notehead>

<Stem id="s1">

<origin>0 0</origin><size>1 1</size>

<value>up</value>

</Stem>

</Note>

<Note id="n2">

<origin>26.678 0</origin><size>1 1</size>

<Notehead id="h2">

<origin>0 0</origin><size>1 1</size>

<value>closed</value>

</Notehead>

<Stem id="s2">

<origin>0 0</origin><size>1 1</size>

<value>up</value>

</Stem>

</Note>

<Note id="n3">

<origin>36.875 2</origin><size>1 1</size>

<Notehead id="h3">

<origin>0 0</origin><size>1 1</size>

<value>closed</value>

</Notehead>

<Stem id="s3">

<origin>0 0</origin><size>1 1</size>

<value>up</value>

</Stem>

</Note>

<Barline>

<origin>47.456 0</origin><size>1 1</size>

<dotted>no</no>

</Barline>

<Note id="n4">

<origin>50.788 2</origin><size>1 1</size>

<Notehead id="h4">

<origin>0 0</origin><size>1 1</size>

<value>open</value>

</Notehead>

<Stem id="s4">

<origin>0 0</origin><size>1 1</size>

<direction>up</direction>

</Stem>

<AugmentationDot id="d1">

<origin>2 1</origin><size>1 1</size>

</AugmentationDot>

</Note>

<SingleBarline>

<origin>70 0</origin><size>1 1</size>

<dotted>no</no>

</Barline>

<LedgerLine noteid="n1">

<origin>15.499 -2</origin><size>1 1</size>

</LedgerLine>

<LedgerLine noteid="n4">

<origin>49.788 -2</origin><size>1 1</size>

</LedgerLine>

</Staff>

</Page>

</Score>

Listing 8-1: A sample XML representation

Discussion

This chapter further examines the decisions made in the analysis. Alternate solu-tions are also discussed and evaluated, as are some issues concerning design-stage modeling. Explored here is the possible simplification of the analysis model, so as to enhance consistency, and expansion of the model by the addition of new objects and attributes. Finally, questions concerning inclusion of logical and performance information are engaged, and examples of implementation solutions are described.

This chapter presents the model for a generic computer graphics system that is capable of free-form graphics representation. The model is similar to that of a program for general-purpose drawing or for presentation applications. Since music notation is a graphic system, a good notation program should be capable of representing and constructing free-form graphics, in at least a two-dimen-sional coordinate system. Therefore, the model developed here is based on a free-form, two-dimensional graphics system.