CSC223, Class 6: UML (1): Basic Class Diagrams Admin: * CLASSPATH. Either of the following works /home/rebelsky/public_html/Courses/CS223/2004F/Examples /home/rebelsky/Web/Courses/CS223/2004F/Examples * Questions on Friday's homework? Daren plans to make extra time for you tonight. (I think.) * A week of eboards: Good, bad, indifferent? Note that each one has two "names" * Teaching strategy: You can read the book, so I'd rather ask you questions that challenge your learning and then ask you to critique each other's answers. * Sketchy outline today so that you can't read the answers to some questions. * Assignment: Read chapters 4, 9, and 10 of Fowler. * Survey: How many of you know CVS? make? Ant? How many of you use it in your normal programming activities? Know CVS: Few Use CVS, in the sense of generating your own CVS commands rather than using ones someone else told you about: A different set Know make: Few Use make, in the sense of writing makefiles: Know Ant: Very few Use Ant, in the sense of writing those silly xml files: Similarly few Overview: * What are the key parts of a class? * What kinds of relationships can there be between classes? * How do interfaces change the situation? * What questions do you have? * Exercise and Critique Key Parts of a Class: * Name * Fields/Attributes * Constructors * Destructors * Methods * Modifiers/Mutators (bang things in Scheme) * Viewers/Observers * Class stuff (shared) (static) * Class methods * Class fields * Constants * How do we represent all of this? +---------------+ | N A M E | +---------------+ | | | ATTRIBUTES | | | +---------------+ | | | METHODS | | | | | +---------------+ * Note: Fields can also be represented by "associations" * Note: We'll need to learn how to do "the class stuff" (A problem to which we will soon return.) * Note: To UMLers, constructors are just a kind of method. * What do you do in UML when you don't know the precise thing to do? public class Coin { int denomination; static long numCoins; static long totalValue; public Coin(int _denomination) { this.denomination = _denomination; ++numCoins; totalValue += _denomination; } } // class Coin pen.println("The U.S. Governement has issued " + Coin.totalValue + " in coins."); * Strategies for dealing with the "how to notate static method"? * Responsible student method: Look it up in the book. Answer: They're underlined. * Irresponsible faculty method: Add a piece of notation; who cares if it's legal UML. * << vs. { vs. [ * Stupid assignment: Find the name of "<<" and ">>" <> * Stuipd assignment: Find the difference between <> and {silly} What are possible relationships between objects/classes? * Containment: One object can contain instances of other objects * Definition: Classes define objects * Numbering: We can use numbers to add information to existing relationships * Inheritance: One class can be derived from another class. (Inverse of inheritance.) * Creation: Objects in one class can create objects in another class. Our Main created a CandyMachineFactory object and passed it to someone else. That CandyMachineFactory object was never a field (or even a variable) of Main. * Use: Objects in one class can use objects and methods in another class, even if those objects are not contained within the class. * System.out.println * Our methods might take those other objects as parameters. * We might create, use, and discard objects. * Grouping: Objects are grouped into packages or something. * Representing these relationships: * Kinds of Lines * Kinds of Arrowheads * Text written next to lines * Other funky symbols * Association (Containment) (Aggregation) * Solid line, Optional Open Arrowhead _____\ / * Points toward the contained/associated class * Might also have numbers to represent arity of relationship or Kleene Star * Inheritance * Solid line, hollow arrowhead * Usually multiple lines converge into tail of arrowhead. * Points toward the super class. * Use (Dependency) * Dotted line, open arrowhead --->