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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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 Another example: JOptionPane is a class in the Swing package.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern