Lập trình Wrox Professional Xcode 3 cho Mac OS part 39 potx

7 166 0
Lập trình Wrox Professional Xcode 3 cho Mac OS part 39 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

CLASS MODEL BROWSER The upper pane in the class model is the class model browser, as shown in Figure 14 - 5. On the left is the list of classes being tracked by the model. Selecting a class displays the class ’ s members in the middle list. Selecting an item in either list displays additional information about that item in the details pane on the right. You can use the dividers between these sections to resize them, within limits. FIGURE 14 - 5 To avoid any confusion, the term “class browser,” or just “browser,” in this chapter refers to the class model browser, not the class browser discussed in Chapter 9. Class modeling can be used to model C++, Java, and Objective - C classes. The terminology used in class modeling tends to be neutral: Properties refer to instance or member variables of a class. Operations refer to class methods, functions, or messages. Protocols refer to either Objective - C protocols or Java interfaces. Categories are Objective - C categories. Packages are Java packages. Not all modeling concepts apply to all languages. Categories only appear when modeling Objective - C classes. Package names only appear when you ’ re modeling Java classes. Multiple - inheritance can only occur with C++ classes. You can customize the browser display a number of different ways. In the lower - left corner of both the class and member lists is a pop - up menu that will alter a list ’ s display. The choices for the class list, shown on the left in Figure 14 - 6, are Flat List and Inheritance Tree. Flat List lists all of the classes alphabetically. Inheritance Tree lists the classes in a hierarchical browser. ➤ ➤ ➤ ➤ ➤ Class Model Browser ❘ 291 c14.indd 291c14.indd 291 1/21/10 3:41:46 PM1/21/10 3:41:46 PM Download at getcoolebook.com 292 ❘ CHAPTER 14 CLASS MODELING The list options for the members list lets you select between Show All Members, Show Properties, and Show Operations. You can resize and reorder the columns for both lists as desired by dragging the column separators or headers. Right/Control - click the column titles to control which columns the list displays, also shown in Figure 14 - 6. Check only those columns you want to see. The menu for both lists includes a Show All Columns command. CLASS MODEL DIAGRAM In the lower portion of the pane is the class diagram, as shown in Figure 14 - 7, and is class modeling ’ s raison d ’ ê tre. The diagram presents a graphic visualization of the class relationships. Note that the browser and diagram show much of the same information, just in different ways. FIGURE 14 - 6 FIGURE 14 - 7 c14.indd 292c14.indd 292 1/21/10 3:41:52 PM1/21/10 3:41:52 PM Download at getcoolebook.com The entire class model diagram is contained on a variable number of pages that look like graph paper. The number of pages automatically expands to encompass the diagram. Nodes Entities in a class model diagram are represented as nodes. At the top of each node is its title. Nodes may optionally show additional detail — quite a bit of detail, if you like. The form and color of the title indicate its type, as listed in the following table: NODE TITLE COLOR NODE TYPE PlainTitle Blue Class < TitleInBrackets > Red Objective - C protocol or Java interface (TitleInParentheses) Green Objective - C category The background color of framework classes is darker than that of classes defi ned in your application. Lines between nodes denote inheritance. The arrow points to the superclass, interface, or category from which the node inherits, conforms, or extends. The possible combination of arrows and lines is listed in the following table: LINE AND ARROW TYPE RELATIONSHIP Solid line with an open arrow Points to the superclass or category that the class inherits Dashed line with an open arrow Points to the interface or protocol that the class adopts Solid line with no arrow Indicates an attached annotation node The compartments below the title detail the members of the class. The Properties member lists the instance variables and the Operations member lists the methods or functions. You can completely hide these details by “ rolling up ” the node, and reveal them again by rolling them down. You accomplish this by using the Design ➪ Roll Up Compartments and Design ➪ Roll Down Compartments commands. The command applies to the currently selected node or nodes. You can also access those same commands by Right/Control+clicking selected nodes. If no nodes are selected, the commands change to Roll Up All and Roll Down All. The lists within the compartments can be individually expanded or collapsed by clicking the disclosure triangle to the left of the compartment title. To collapse or expand all the compartments Class Model Diagram ❘ 293 c14.indd 293c14.indd 293 1/21/10 3:41:53 PM1/21/10 3:41:53 PM Download at getcoolebook.com 294 ❘ CHAPTER 14 CLASS MODELING The members of a class may optionally display their visibility (private, protected, or public), type, return type, or method parameters. All of these display options are set in the General tab of the diagram ’ s Info window. With the selection tool, click anywhere on the background of the diagram so that no nodes are selected, and then choose File ➪ Get Info (Command+I). Switch to the General tab and the various display options appear at the top of the window, as shown in Figure 14 - 9. The Show Visibility option refers to the scope or accessibility of class members, indicated by a small icon next to each member. The possibilities are as follows: VISIBILITY/SCOPE SYMBOL Private red circle Package orange triangle (pointing down) Protected yellow triangle (pointing up) Public green square FIGURE 14-8 FIGURE 14-9 at once, select a node or nodes and choose either the Design ➪ Collapse Compartments or Design ➪ Expand Compartments command. When no nodes are selected, the commands change to Design ➪ Collapse All and Design ➪ Expand All. Figure 14 - 8 shows a variety of node states: the categories on the left have been rolled up, the classes have been selectively expanded, and the categories on the right have been fully expanded. c14.indd 294c14.indd 294 1/21/10 3:41:53 PM1/21/10 3:41:53 PM Download at getcoolebook.com The Show Property Type option includes the variable type after each class property. Show Operation Return Type shows the return value type of each operation. This may appear before or after the operation name, depending on the language being modeled. The Show Operation Parameter List option includes the entire parameter list of each operation, and can make for some very wide class nodes. The Show Package option applies only to Java. If you select this option, the package name appears below the name of the class or interface in the node ’ s title compartment. Figure 14 - 10 shows a diagram with all the display options turned on (left) and off (right). Static, also known as class, operations are underlined. This is one display option that is not customizable. FIGURE 14-10 Tools Five tools, listed in the following table, are displayed in the palette in the lower - left corner of the class diagram. To use a tool, click it. The currently selected tool is highlighted, and the cursor refl ects the current tool whenever it is in the class diagram pane. TOOL DESCRIPTION Arrow Selection tool. Used to select elements, move, expand, and resize nodes. This is the default tool. Note Note tool. Creates annotation nodes. Line Line tool. Connects nodes. Magnifying Glass Zoom tool. Enlarges or shrinks the diagram display. Hand Drag tool. Pans the diagram around in the window. Choose the Arrow tool whenever you need to select, move, resize, or otherwise manipulate the nodes in a diagram. The Note and Line tools are described later in the “ Adding Annotations ” section. Class Model Diagram ❘ 295 c14.indd 295c14.indd 295 1/21/10 3:41:54 PM1/21/10 3:41:54 PM Download at getcoolebook.com 296 ❘ CHAPTER 14 CLASS MODELING The Magnifying Glass and Hand tools are ways of navigating the diagram, and are described in the next section. Navigation Moving around the class diagram is pretty straightforward. You can use the scroll bars at the bottom and right side of the pane to scroll the diagram. You can also select the Hand tool and drag the diagram around. Reduce or magnify the diagram by selecting a magnifi cation amount in the zoom control in the lower - right corner of the pane. You can select a specifi c magnifi cation from between 10 and 1600 percent. Use the Magnifying Glass tool to incrementally zoom the diagram. Select the tool and click anywhere in the class diagram pane to increase to the next zoom magnifi cation in the menu. Hold down the Option key and a minus sign ( – ) appears in the tool. Click with the Option key held down and the diagram is shrunk to the next zoom magnifi cation level in the menu. To zoom the diagram to fi t an arbitrary portion of the diagram, drag out a rectangle using the Magnifying Glass tool. The image zooms so that the approximate area of the diagram selected fi lls the pane. The Design ➪ Diagram ➪ Zoom In (Control+Shift+Command+=) and Design ➪ Diagram ➪ Zoom Out (Control+Command+ – ) commands are equivalent to clicking, or Option+clicking, with the Magnifying Glass tool. To scale the display to fi t the entire diagram in the pane, choose the Design ➪ Diagram ➪ Zoom To Fit (Control+Command+=) command. Selecting You can select class nodes in a variety of ways. Selecting a class also causes the diagram to scroll if the selected class is beyond the edge of the visible diagram. Click a node to select it. Drag out a rectangle using the Arrow tool to select all of the nodes that intersect the rectangle. Class selection in the diagram and browser are linked. Selecting a class in the browser selects the same class in the diagram, and vice versa. The Functions menu in a class diagram lists all of the classes in the model, as shown in Figure 14 - 11. Choosing one selects that class in both the browser and diagram, and scrolls to make both visible. FIGURE 14-11 c14.indd 296c14.indd 296 1/21/10 3:41:54 PM1/21/10 3:41:54 PM Download at getcoolebook.com You can add class nodes to the selection by holding down the Shift key while clicking unselected nodes or dragging out a selection rectangle. Nodes can be individually removed from a selection by clicking a selected node while holding down the Shift key. It may be necessary to click the background area or the edge of a node; clicking the node ’ s title or a member may not deselect it. You can also type the fi rst few letters of a class name. When listed alphabetically, the fi rst class that matches the characters typed is selected. Quick - Jump to Source Double - click any class or member in the class browser, and Xcode jumps to its declaration in the source code. In the class diagram, Right/Control+click on a node, as shown in Figure 14 - 12, and choose one of the commands: Go to Declaration Go to Defi nition Go to Documentation These same three commands can be found in the Design ➪ Class Model submenu. If an individual property or operation in the node is selected, Xcode jumps to that specifi c instance variable or method. Otherwise, you are taken to the class ’ s defi nition, implementation, or documentation. If a class or method appears in the API documentation, a small “ book ” icon appears next to its name in the browser. Clicking the book icon jumps to its documentation, and is the same as choosing the Design ➪ Class Model ➪ Go to Documentation command. EDITING A CLASS MODEL “ Editing ” a class diagram is limited to customizing its appearance. As mentioned at the beginning of this chapter, you can ’ t alter the defi nition of a class in a class model. Class modeling is strictly a visualization tool. Any changes you make will be (mostly) cosmetic. That said, you can alter the layout and appearance of the class diagram signifi cantly, which can profoundly infl uence its effectiveness as a programming aid. Moving Nodes The main point of class diagrams is to visually represent the relationship between classes. Creating a pleasing and readable distribution of class nodes is, therefore, paramount to creating a useful class ➤ ➤ ➤ FIGURE 14-12 Editing a Class Model ❘ 297 c14.indd 297c14.indd 297 1/21/10 3:41:57 PM1/21/10 3:41:57 PM Download at getcoolebook.com . collapse or expand all the compartments Class Model Diagram ❘ 2 93 c14.indd 293c14.indd 2 93 1/21/10 3: 41: 53 PM1/21/10 3: 41: 53 PM Download at getcoolebook.com 294 ❘ CHAPTER 14 CLASS MODELING The. lists within the compartments can be individually expanded or collapsed by clicking the disclosure triangle to the left of the compartment title. To collapse or expand all the compartments Class. FIGURE 14-8 FIGURE 14-9 at once, select a node or nodes and choose either the Design ➪ Collapse Compartments or Design ➪ Expand Compartments command. When no nodes are selected, the commands

Ngày đăng: 04/07/2014, 06:20

Tài liệu cùng người dùng

Tài liệu liên quan