CIS-123 Home http://www.c-jump.com/bcc/c123c/c123syllabus.htm

Chapter 1, Classes of objects


  1. Week 2, Chapter 1, Classes of objects
  2. Classes of Objects and Instances of Objects
  3. Object attributes
  4. UML Class Diagram Video Notes
  5. Sizes of objects
  6. Object design principles
  7. Object Data Summary

1. Week 2, Chapter 1, Classes of objects

  • Classes vs. objects

  • There are no classes and there are no objects.

  • However, there are classes of objects and instances of objects.

  • What exactly is a class?

    • class is a blueprint of an object:
      blueprint

  • What exactly is an object?

    • a real thing, actual instance of the class:
      object instances

2. Classes of Objects and Instances of Objects


3. Object attributes


  • Using Java code to describe a class:

    
    public class Person {
        // Attributes
        private String name;
    
        private String address;
    
        // Java methods
        public String getName() {
            return name;
        }
    
        public void setName( String name_ ) {
            name = name_;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress( String address_ ) {
            address = address_;
        }
    }
    
    
  • Using UML to model a class diagram:

     

    Person
    -name:String
    -address:String
    +getName:String
    +setName:void
    +getAddress:String
    +setAddress:void

4. UML Class Diagram Video Notes


5. Sizes of objects


  • Size of an object is determined by

    • number of data items (aka data variables)

    • calculated as the total number of bytes in each data item.

  • Note: number of Java methods or C++ functions does not measure the object size.

    • Although each method can be measured in the number of bytes of the actual code, there is not necessarily a physical copy of one method for each object. Rather, each object points to the same physical code.

    sizes of objects

6. Object design principles


  • Keep objects small:

    • minimum required data

    • minimum methods required by functionality.

  • Each object should be designed to have specific tasks.

  • A system should contain many small interacting objects rather than a few large objects.

    small interacting objects

7. Object Data Summary