lecture05

lecture05 - Class 5: Classes and Objects Class 1.00/1.001 -...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Class 5: Classes and Objects Class 5: Classes and Objects 1.00/1.001 - Introduction to Computation and Problem Solving Fall 2005 Objects Objects are ‘things’ Recall the description of libraries, books, paperback books from Session 1 We decompose programming problems into a set of objects that are an intuitive representation of the situation. Examples: A building List the objects Each of these may contain other objects. List them Data packets going through a router List the objects Each of these may contain other objects. List them 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Objects A building Objects: Beam, Slab, Wall, Window, Pipe, AirVent, WaterBoiler, …. Window contains GlassPane, Sash, Members such as GlassPane have attributes such as coating, height, width Data packets going through a router Objects: Network Link In and Link Out, Router. Each of these may contain other objects: Network link: contains data packets Router: contains packet queues, buffers, processor Bank Example Customer: Data fields: List them Methods or behaviors: List them Account: Data fields: List them Methods: List them Transactions Fields: List them Methods: List them 2
Background image of page 2
Bank Example Customer: Data fields: name, address, occupation, dateOfBirth, … Methods or behaviors: Create new, changeAddress, changeName, delete Account: Data fields: Customer, balance, type, transactions Methods: Create, close, checkBalance, reportTransactions Transactions Fields: Deposit, Withdrawl, WireTransfer, payCheck, ATMWithdrawl Methods: Create, executeTransaction, Bird Example public class Head( ) { ...... } public class Body( ) { ...... } public class Wing( ) { ...... public void changeColor( ) { ...... } } public class Bird( ) { ...... Head birdHead= new Head( ); Wing leftWing= new Wing( ); Wing rightWing= new Wing( ); public Wing getWing( ) { ...... } public void fly( ) { ...... } public void changeStatus( ) { ...... } } public class Scene( ) { ...... Bird bird= new Bird( ); Wing wing= bird.getWing( ); public void changeWingColor( ) { wing.changeColor( ); } public void changeFlyStatus( ) { bird.changeStatus( ); } } 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Modeling Objects Modeling objects (choosing the right problem representation) is like modeling in general There is generally no single ‘right’ answer (even in our problem sets!) There are standard patterns/paradigms that have been found to be flexible, correct, efficient, etc. We will introduce you to ‘software patterns’ There are many standard objects in Java You can build your own library of objects in Java that you can then use in future programs Classes A class is a pattern or template from which objects are made You may have many birds in a simulation One bird class (or more if there’s more than one type of bird) Many bird objects (actual instances of birds) Simulation
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

lecture05 - Class 5: Classes and Objects Class 1.00/1.001 -...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online