Java Syntax, Java Conventions, CSE 115 Conventions (Part 3)XX - ReferencesXXI – Assignment OperatorReview of CompositionClassA has a ClassBXXII – Sending MessagesSyntax of a Method CallFour Main Parts of a MethodCardinalityAssociation RelationshipDog knows a TreeJava Syntax, Java Conventions, CSE 115 Conventions (Part 3)CSE 115 Spring 2006February 6, 8 & 10, 2006XX - ReferencesDeclaring an instance variable creates a reference.All references are initially null.We assign a value to a reference using the assignment operatorXXI – Assignment Operator=Takes the value on the right and assigns it to the variable on the left:_varName = new Object();Review of CompositionDeclare an instance variableCreate an instance of the subpartAssign the instance to the instance variableNote that steps two and three above actually happen in one line of code.ClassA has a ClassBpublic class ClassA {private ClassB _classB;public ClassB() {_classB = new ClassB();}}XXII – Sending MessagesAsking/telling an object to do something, or asking it to perform one of its capabilities.Capabilities are methods inside our class definition.In code, we would be performing a method call/method invocation.Syntax of a Method CallinstanceName.methodName();•Q: What is the name of the () and what are the () used for in a method call?Four Main Parts of a MethodSenderReceiverReturn TypeParametersDescribe the purpose of each of these and what they correspond to in code.CardinalityThe number of a certain type of relationship between objects. An Applet can have 5 BouncingBalls. That means there are 5 instances of the “has-a” relationship present.Association Relationship“knows a” relationshipIn UML, represented by an arrow ( → )In code:Declare an instance variable of the associate.In constructor, accept a parameter whose type is the same as that of the associateAssign the value of the parameter to the instance variableDog knows a Treepublic class Dog {private Tree _tree;public Dog(Tree tree) {_tree =
View Full Document