Kinesia Online Course
Object Oriented Programming
Kinesia LLC, 2003
    1. A Little Taste of Java
    2. Abstraction and Modeling
    3. Objects and Classes
    4. Object Interactions
    5. UML and Relationships between Objects
    6. Collection of Objects
    7. Some Final Concepts
    8. Object Modeling and Use Cases
    9. Modeling of Dynamic Behavaior and Sequence Diagrams
    10. A Deeper Look at Java
    11. Java Layout
    12. Java Events
    
    A new philosophy, a new way of life, is not given for
    nothing.  It has to be paid dearly for and only
    acquired with much patience and great effort.
    
    					Fyodor Dostoevsky
    
    

    Object Interactions

    1. Events Drive Object Collaboration

      Process of OO software development involves:

    2. properly establishing the functional requirements for, and overall mission of, an application

    3. Designing the necessary classes

    4. intantiating classes to obtain objects

    5. executing objects through external triggering events
    6. Example:

      an anthill

    7. Method Signatures

      Method signature ( header ) -- The method's name and the number of its parameters and the types of its parameters as well as its return type.
      The purpose is to indicate the method's name and the number of its parameters and the types of its parameters.

      Java Syntax:

      dataType methodName ( parameter1Type parameter1 ...)

      ( In C++, a method signature is exactly the same thing as a function prototype. )

      How do we represent in code that a method is being invoked on an object?

      Ans: We create what is known as a message.

      Example

        //Instantiate a Student Object
      
        //Send a message to Student object 'x', asking it to register for course
        //CS 420, section 1
        x.registerForCourse( "CS 420", 1 );
        

    8. Delegation

      If a request is made of an object A and, in fufilling the request, A in turn requests assistance from another object B, this is known as delegation by A to B.

      The delegated object can work 'behind the scene'.

      same sense as real world examples.

      Example: Java AWT Delegation Event Model

    9. Event types are encapsulated in a class hierarchy rooted at java.util.EventObject. An event is propagated from a "Source" object to a "Listener" object by invoking a method on the listener and passing in the instance of the event subclass which defines the event type generated.

    10. A Listener is an object that implements a specific EventListener interface extended from the generic java.util.EventListener. An EventListener interface defines one or more methods which are to be invoked by the event source in response to each specific event type handled by the interface.

    11. An Event Source is an object which originates or "fires" events. The source defines the set of events it emits by providing a set of set<EventType>Listener (for single-cast) and/or add<EventType>Listener (for mult-cast) methods which are used to register specific listeners for those events.

    12. In an AWT program, the event source is typically a GUI component and the listener is commonly an "adapter" object which implements the appropriate listener (or set of listeners) in order for an application to control the flow/handling of events. The listener object could also be another AWT component which implements one or more listener interfaces for the purpose of hooking GUI objects up to each other.
    13. Access to Objects

      The only way that an ojbect A can pass a message to object B is if A has access to a handle on B. This can happen in several ways:

    14. Object A maintains a handle/reference to B as one of A's attributes.

        class Student {
          //Attributes
          String name;
          Professor  advisor;		//handle to Professor object
          //....
        }
        

    15. Object A is handed a reference to B as an argument of one of A's methods.

        Student s;
        Course  c;
        .....
        c.resister ( s );
        .....
        

    16. Object B is global.

    17. Object A explicilty requests a handle/reference to B by calling a method on some third object C. ( complex )

    18. Objects as Clients and Servers/Agents

      c.register( s );

      	Course object c ~ client	( requesting service )
       	

      Student object s ~ server ( providing service: e.g. getTranscript() )

        publice static void main( String [] args )
        {
          Course c = new Course();
          Student s = new Student();
          .....
          //invoke a method on Course object c
          c.resister ( s );
          .....
        }
        
      The main() method is considered to be client code relative to Course object c because it calls upon c to perform its register() method as a service.

        class Course {
        .....
          boolean register ( Student s ) {
      	//Request a handle on a the Transciprt object of Student s
      	Transcript t = s.getTranscript();
      
      	//now, request a service on Transcript object t,
      	//  assuming that c2 is a handle on some prerequisite course ...
      	if ( t.successfullyCompleted ( c2 ) 
      	  return true;
      	else
      	  return false;
        	......
          }
        .....
        }
        
      register() method body is considered to be client code relative to both Student object s and Transcript object t because this code calls upon s and to to each perform a service

      Whenever an object A is a client of object B, object B in turn can be considered as a server or agent of A.

    19. Information Hiding, Visibility

      Information Hiding goes hand by hand with Encapsulation as it is implemented within a class by making its attributes and methods not visible from outside its boundary.

    20. When members (attributes and methods) of a class are private, they are not visible by any other Object of a different class. They are only accessible to their class.

    21. The norm in Object-Oriented Programming is to have as many attributes and methods private as possible.
    22. Why information hiding?

    23. Security, avoiding unnecessary code tampering.

    24. De-coupling. In Object-Oriented Programming high de-coupling is desirable. Information Hiding aids in keeping high de-coupling among objects, as private members of a class are not visible and therefore cannot be used to communicate among objects.
    25. JAVA ways of implementing Information Hiding:

      By the use of the 'private' modifier in front of the member.

      Example of JAVA class showing Information Hiding:

      class Treasure
      {
        private double amount;
        private int codedNumber ;
      
        Treasure(double tmpMoney)	//constructor
        {
          amount = tmpMoney;
        }
      
        private void calculate()	//private method
        {
          amount*= codedNumber;
        }
        .....
      }
      
        

      Public visibility:

      public methods and attributes can be accessed by client code via dot notation
      class Treasure
      {
        private double amount;
        private int codedNumber ;
      
        Treasure(double tmpMoney)	//constructor
        {
          amount = tmpMoney;
        }
        
        .....
      
        private void calculate()	//private method
        {
          amount*= codedNumber;
        }
      
        public double getValue()	//public method
        {
          return amount;
        }
        .....
      }
      
        

      Protected visibility:

      protected methods and attributes can be accessed by the class and its subclasses

    26. Accessor and Modifier/Mutator Methods

      class Treasure
      {
        private double amount;
        private int codedNumber ;
      
        Treasure(double tmpMoney)	//constructor
        {
          amount = tmpMoney;
        }
        
        .....
      
        private void calculate()	//modifier/mutator
        {
          amount*= codedNumber;
        }
      
        public double getValue()	//accessor
        {
          return amount;
        }
        .....
      }