Intro to Computer Science II
Intro to Computer Science II CSCI 204
Popular in Course
Popular in ComputerScienence
This 9 page Class Notes was uploaded by Laurianne Mante on Saturday October 3, 2015. The Class Notes belongs to CSCI 204 at Bucknell University taught by Staff in Fall. Since its upload, it has received 62 views. For similar materials see /class/218093/csci-204-bucknell-university in ComputerScienence at Bucknell University.
Reviews for Intro to Computer Science II
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/03/15
BUCKNELL UNIVERSITY CSCI 204 INTRODUCTION TO UML DIAGRAMS IN DIA BY KATIE HEISE What is Dia Dia is a drawing program that can be used to create diagrams Dia includes a variety of basic tools like lines and boxes and can load sheets collections of tools that are used in a specific type of diagram Most diagram objects have handles to which lines can be connected to form graph structures When the objects are moved or resized the connections will follow their respective objects In this course we will concentrate on working with UML class boxes What is UML Unified Modeling Language UML diagrams are class diagrams that allow documentation of data members memberfunctions interfaces and relationships between classes UML is one way to represent various views of a piece of software the user s or clients view or the source code for example The diagrams provide a logical structure or outline for writing code Startinq Dia For UML Diaqrams on the Sun Type dia amp at the command line prompt and press Enter The main window should appear after an introductory title dialog Select UML from the menu in the middle of the Dia window A Figure1 collection of tools for working with UML will appear below the menu See Figure 1 at right To open an existing le choose Open from the File menu Double click the desired file in the Open Diagram dialog or select the file and click OK Skip steps 4 and 5 Create a new diagram by clicking on New from the File menu You will see an empty grid Select the Create a class icon Then left click on the grid Your screen should resemble Figure 2 N 9 Lefi click a 0 cm H E Electric Figure 2 F5 Fluwchan Jigsaw Ladder Luglc MSE Misc Nelwurk Select SADTlDEFU SDL class icon Wor ngw h UML D grams Generat notes To access menus whtte worxtng tn the gno wtnoow rtght cttcx on the gno or on the obtect oftnterest Don t for et to saye ustng File a Save CTRLVS orFiIe a Save As CTRLVW Open an extsttng ttte trom the Dta matn wtnoow orfrom the gno by setecttng File a Open CTRLVO do I edit myclass To set the ttetos tn yourctass box setect the box by tert cttcxtng Doubte cttcxwtthtn the ctass box to brtng up the Properttes wtnoow orrtght cttcx to brtn up the menu and setect Dialogs a Pro erties Seethe BanxAccount exam te on the tottowtng pages forspect c tntormatton on creattng and eotttng meantngtut ctass dtagrams ustng the Properttes wtnoow are classes organized ctass dtagrams are boxes dtytoeo tnto three secttons The ctass name appears at the top of the box The data contatneo by each obtect otthe ctass ts found tn the mtodte sectton and the operattons or tuncttons compose the ttnat sectton The ctass otagram aboye proytoes a great oeat of tnformattort about the BanxAccount ctass BanxAccount obtect has two attrtbutes Batance and Name atance ts a ubte 0 Name ts a strtng BankAccounts may be mantputateo by seyerat operattons o The constructor returns a new tnstance of BanxAccount and taxes two arguments s a doubte and a stnng getBatance returns a doubte and taxes no arguments oooo depostt taxes a doubte argument Note that tnstead ofthe C VOld wlthdraw double amount for examp e UML uses the Syntax wlthdraw amountmiouble votd t5 not used tn UML tndtcates that a data member ormemberfunctton t5 pubhc 9 tndtcates that tt t5 prtvate Transtattng the ctass otagram tnto c ytetds the foHthng code class Hanknccnunl s nuhle HalanCE suing ants public Hamecnunl dnuhle ammlnl suing nsntst cunslxuclnx dnuhle gsuislsnestt suing gel amen void withdzaw1dnuhle mnnnn void depusil dnuhle ammuan Example Creating the BankAccount Class Double click inside a new class box to open the Properties window Figure 3 Step 1 of aankAccount Speci cation Pr n rti UNH eria Enter name of eiass titties i Operates iremnaes Ammutes visibie u Suppiess Ammutes r Opeiatiuns visibie J Suppiess upeiatiuns Kind Font Size mm A Jr Abstiact cemeteonete 4 im CiassName Heneteaeeme A inn Abstiactciass Hewetieaeemuomiuue 4 inn Fuiegiuund Cuiui Eackgiuund Cuiui t l t I i OK J Am cese Figure 4 Step 2 of EankAccount Speci cation Adding an Attribute Si onpevtte UMmeiax MA I Ciick New to and Ciass A iibutes Opeyatiuns Tempiates eaen nevvattnbute uata member New Add name and type at tne attribute Vaiue NEWS Eaiance Visibiiity APubii Pi ate cnuuse Visibiiity w J Ciasss Pmmd Dptiun e pnvate in 7 this case impenem OK i new i cese Flgure 5 Step 3 of EankAccount Speclflca on Addlng the constructor j onDevtle UMLrClam J Click New Class I Attributes OpEvatiuns Templates to add the unstructur Give the Jamccu m WWWquot ClicKNew constructor the 1 El and each the class parameter Visibility mu Type cunstmctur Specify the We 2 type Polymorphic Virtual 4 m2 parametmame Stereotype d type SEtVIsIbIIItytu DEV val Publlc SD wem Direction unde ned A1 pmgrams can create 4 BankAccount unlects OK i Apply l cm i In UML constructors do not have to share the name ofthe class Constructors are identi ed with the stereotype ltltconsthctorgtgt a stereotype anything ofthe orm ltlt is a ded to an aspect o a UML diagram the meaning ofthat aspect becomes more specialized In the case of constructor the operation is forced to reate and initialize a new 39 type A constructor quot ject object ofthe appropriate should not be documented as returning a type it instead creates a new at W n m rrer it la l lul crass innings Operarmnslwam First click New tn add eaen new structur EanKAccnunlamuunl uuunrenane string New Delete netrun Move up Muve down p Pmmms rrtnerunetrun has Return type at 3 Elm parameters wnrre tne tne runetrun mm 1 NEW f runetrun name rs leave blank rr mum F DEW highlighted in tne list at Vina Q thetup urtne wrnuuw Muveup lrEKNewtu add eaen J 0 MW WWquot tne name and type urtne S I my Parameter data parameter e visr n A member inheritance type Pulymtrphrc virtual 4 mm mm JQuery T E W ublr in this n1 F E Der value Dneermn Unde ned 4 0K Apply l Cluse quot39 J 39 39 ration click on L 39 L I upe W F the p t mm 1414 Left click on an item in the list at the top ofthe window to select the attribute or operation to be modi ed To i a arameter select the function and then click on the parameter Blue highlighting indicates the selected components For const functions or const or const amp reference parameters enter const before the type name in the operations or parameters Type text box on the Operations tab ofthe Properties window and if appropriate a after the type name Add const to data members in the same way under the Attributes tab ofthe Properties window Printing a Diagram 4 r 39 Dia tends to 39 quot g quot g L quot several pages The dark blue lines on the grid mark the boundaries of each printed page To solve this problem try one of the following 0 Select File a Page Setup by right clicking on the grid and select the Fit to option under Scaling The rst value is the number of pages the diagrams on the grid wrll occupy horizontally and the second value is the number of pages the diagrams will occupy vertically This option will usually be set to1 b 1 Select File a Page Setup as described above desired value 30 o en works well and set Scale under Scaling to the Print the diagram with the File a Print Diagram CTRLP command Type the appropriate printer command in the text box a2ps lec for Dana 231 and aZps 7P1w3 for Dana 320 Note that you may also print to a le Modeling Relationships Associations Before writing code it helps to produce a model of the concepts involved which can lead to easy identification of the necessary classes functions and variables The simplest way to do this is to create a class box for each of the obvious classes in the problem and add associations between them Click on the Association icon shown at right and draw a link between two classes on the grid by left clicking and dragging Figure 8 shows the classes expected in the initial design of software that models a university Since so many classes are involved the details of operations and attributes are omitted leaving only the class name in each class box To achieve this effect double click on a class box to open the Properties window go to the Class tab and clear the check boxes for Attributes visible and Operations visible Fi ure 8 Associations Modeling a small campus Taken from htt wwwcscicsusbedudicksam esum1htm Associations can be modified to provide more specific information Double click on the association the dark line connecting two classes to bring up the Association window All fields are optional Only one of the four Aggregate and Composition boxes may be checked at any given time Dependencies and composition will be covered in more detail in the next few sections of this tutorial See Figure 10 on the next page for a revised version of Figure 8 Association and role names and multiplicities have been added dwmu Name Give the association a What role does W t does it each class play in name ha Direction F m BioA J represent Side Side 37 the association 239 Role Salectthe jirection 0ft 5 Multiplicity Multiplicity Anumber How many objects ofthe class on this side association None From A to B or From B to A J Show arrow J Show arrow None is the default VJ Aggregate J Aggregate can be involved in the association For Aggregation the J Composition J Composition a oneto many other class is part 7 i T i 77 T i f association for of this one but also example side As has an independent 0K Apply I C1035 multiplicity would be existence 39 1 an si e B s 0 Composition the other class Figure 9 The Association Window is part of this class possesses a component of the other class n teen 391 mm Ass m Mammyan m w Decslamquot Cm mm 1 has quot quot em ta n w Enmlmm n U mum 1n 7 Manama SnI college Awmmmn names and numpmtesneve been added Yaken m mt Wvwvusu 851 mummy esmn mm Dependencies S stmpte t the nude et dass A eentamstne name at anetner etass m the dtagram dass EL Regarmess ettn Humu t The Create a dependency mun S snewn at ngnt new mm we we n t e e um new m mm In me e vnxd hInIvalemntaunnH C SSAHEPEWS Dquot 65835 hxmlmmmnnn lt Dta and UML prevme mare omposition In general terms omposition is a has aquot relationship For example a person object would have arms egs and e es as arts A ca an engine a chassis an a set oftires C structs are prime examples of something that is at heart a collection of parts And data members are parts of the state of each object ofa class UML has special notation to show a composition relationship Add a general association i i 4 n u g for the side with the class that has a component ofthe other class ortype Figureis UML uses a black diamond to indicate that an item is stored within Course anotherpiece of data and to indicate that a class of objects has my Time 2 responsibility temporary or permanent for the existenceof one or ways vectorwap more objects ofthe class at the other end ofthe association W en an Item is stored Inside an ob ec the creation or deletion ofthe object will automatically cause the creation or deletion of its parts In Figure 13 for example the creation ofCourse object causes a vector of Day 0 jects and an array ofTime ob39ects to be created These data structures are part ofthe Course object s state and will be eliminated when the Course is deleted or falls out of scope e has a set ufDays and taxes piaee between 2 Times 7 beginning and ending Dial UML Resources Feel free to experiment with Dia and with the more advanced options for UML diagrams The following websites may help httpViMIiiJysatorliuselalladiadiatutJallallhtml Dia tutorial installation the basics and advanced formatting o httpViMANrationalcomumll UML resource center and documentation from the developers httplWWiNcscicsusbedudickcs202lab02html Very good resource follow links to nd information on basic and more advanced topics httplWWiNcscicsusbedudicksamplesluml1html Simple modeling techniques relationships between C and UML