Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 03 – Class Design, Object Discovery and Use Richard Salomon Centre for Information and Communication Technology Box Hill Institute of TAFE
January 29, 2016January 29, 2016January 29, 2016Slide2 Copyright Box Hill Institute Contents at a Glance Steps in Creating an Object Steps in Creating an Object Discovery of Objects Discovery of Objects Class Definition Class Definition Use of Objects Use of Objects Pass by value Pass by value
January 29, 2016January 29, 2016January 29, 2016Slide3 Copyright Box Hill Institute Steps in Creating an Object 1. Design the object attributes and behaviours 2. Define the object and create a class definition (blueprint for the object) 3. Create an object – instantiate 4. Use the object
January 29, 2016January 29, 2016January 29, 2016Slide4 Copyright Box Hill Institute Discovery of Objects Write a simple description of the what your program is about, including its purpose and intended usage Write a simple description of the what your program is about, including its purpose and intended usage Underline all nouns and adjectives in one colour. The nouns and adjectives are potential objects and fields, but not all make sense to be used. Underline all nouns and adjectives in one colour. The nouns and adjectives are potential objects and fields, but not all make sense to be used.
January 29, 2016January 29, 2016January 29, 2016Slide5 Copyright Box Hill Institute Discovery of Objects Next underline al the verbs and adverbs in another colour. Next underline al the verbs and adverbs in another colour. The verbs and adverbs are your potential methods The verbs and adverbs are your potential methods Now define the classes, using the appropriate nouns and adjectives for attributes and the appropriate verbs and adverbs for the methods Now define the classes, using the appropriate nouns and adjectives for attributes and the appropriate verbs and adverbs for the methods
January 29, 2016January 29, 2016January 29, 2016Slide6 Copyright Box Hill Institute Class Definition Don’t make the class too broad Don’t make the class too broad You may have many classes You may have many classes It is better to have more tightly defined classes than fewer broad classes It is better to have more tightly defined classes than fewer broad classes A constructor method is required to create an object. A constructor method is required to create an object.
January 29, 2016January 29, 2016January 29, 2016Slide7 Copyright Box Hill Institute A programmer may choose not to define a constructor. In such a case, just use a null constructor. A programmer may choose not to define a constructor. In such a case, just use a null constructor. Standard methods are setters (mutators) and getters (accessors). Standard methods are setters (mutators) and getters (accessors). Custom methods are used to implement the application rules. Custom methods are used to implement the application rules. Class Definition
January 29, 2016January 29, 2016January 29, 2016Slide8 Copyright Box Hill Institute Use of Objects Objects interact with each other to accomplish different tasks Objects interact with each other to accomplish different tasks This interaction occurs when one object uses the public methods of the other object This interaction occurs when one object uses the public methods of the other object The dot operator is used to gain access to these methods. The dot operator is used to gain access to these methods. Object instance data is accessed through the reference variable of the object Object instance data is accessed through the reference variable of the object
January 29, 2016January 29, 2016January 29, 2016Slide9 Copyright Box Hill Institute Use of Objects Class data is accessed through the use of the class name Class data is accessed through the use of the class name Only non-private data or methods are accessible to other objects Only non-private data or methods are accessible to other objects Python treats all classes and attributes (data and methods) as public by default Python treats all classes and attributes (data and methods) as public by default
January 29, 2016January 29, 2016January 29, 2016Slide10 Copyright Box Hill Institute Pass by value A copy of the variable value is passed. The original variable value remains unchanged A copy of the variable value is passed. The original variable value remains unchanged Return value is a copy of the local variable value NB the data type of the return value must match the data type of the method Return value is a copy of the local variable value NB the data type of the return value must match the data type of the method