This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.001 Tutorial 9 NotesTA: Gerald Dalley11–12 Apr 2005Announcements• The tutor’s version of the online lectures use an oldversion of the object system.• OOP II Lecture slide 30 is incorrect.• Problem Set 8 due on Tuesday. Note that the ob-ject systems used in the problem set are older, sim-pler, and less p owerful versions compared to the onein project 4 (despite what the intro text says inPS.8.1.1).• Email me ([email protected]) your design plan forproject 4 by 6PM on Wednesday 13 April 2005 (orearlier!).• Project 4 is due before 6PM on 15 April. See theclarifications on the web and in your email.• No class/tutorials/problem sets on 18–20 April. Ifyou’d like a review session for the quiz, email meyour availability on the 18th, 19th, and 20thso I canschedule a few of them.• Quiz 2: Wednesday 20 April, 7:30-9:30PM, in 32-123and 34-101.Object-Oriented ProgrammingThe High LevelAnother “paradigm” for thinking about program-ming (like “functional programming” or “imperativeprogramming”). Not necessarily better, just differ-ent. The idea is to combine the data and the opera-tions performed on that data into one blob. Then, allthe data and operations are combined, which makesextending the system easier later on.Note to Java and C++ programmers: all membervariables are are private.In our object-oriented system, the implementationis based on messages. To request that an object doessomething, the ask procedure first finds the metho d,then it evaluates that method based on the rest of itsinput. For example, (ask car ’park ’carefully)searches car for a method tagged park, then evalu-ates it with ’carefully as its only argument.In our system, we have foo and create-foo pro-cedures. The foo procedure defines how the ob-ject works — the methods it has, the state variablesthat are part of the object. It is sometimes called a“maker.” The create-foo procedure builds an in-stance of the object — an actual piece of data thatis that type of object.Objects have the nice property that they can in-herit from other objects. For example, a personis a mobile-thing, which is a thing, which is anamed-object, which is a root-object. By inher-iting, you can define new objects that have differentbehaviors, but only write a small bit of code.The Low LevelIn a little bit, we’ll see what the internal represen-tation is for an object. This year’s representation isquite a bit more complex than in previous terms.• Instance: a list containing the tag instanceand a pointer to the message handler. Exam-ple: (create-place ’10-250) returns a placeinstance.• Message handler: a procedure that works inconjunction with ask to find and evaluate meth-ods. The message handler’s environment keeps(1) a list of the methods for the instance’s classand (2) a list of all the superclasses of the in-stance’s class.• Method: a procedure created by a maker thatcan be evaluated by the message handler. It hasaccess to parameters of the maker and to any lo-cal state for the instance (created by let state-ments in the maker. Example: ADD-EXIT is amethod of place.• Maker: a procedure used to set up a new in-stance. A maker procedure always takes an ar-gument called self that is a pointer to the in-stance. You should never call the maker directly.Example: place.• Constructor: a thin wrapper around the makerthat uses create-instance to create a new in-stance, make it into the desired type of ob-ject, and install it in the world (if the in-stance has a method called INSTALL). Example:create-place.The point of all this is to have one piece of datathat represents the object itself — the instance isthe object.1Warmup Exercise 1Consider the expression(ask (ask me ’location) ’name)What kind of value does (ask me ’location)return here?an instance of type place.What other messages, besides name, can you send tothis value?place: EXIT, EXIT-TOWARDS, ADD-EXITcontainer: THINGS, HAVE-THING?, ADD-THING,DEL-THINGnamed-object: NAME, INSTALL, DESTROYroot-object: IS-A, TYPE, METHODSWarmup Exercise 2Look through the code in objtypes.scm to discoverwhich classes are defined in this system and howthe classes are related. For example, place is asubclass of named-object. Also look through thecode in setup.scm to see what the world lookslike. Draw a class diagram like the ones presentedin lecture. You will find such a diagram helpful(maybe indispensable) in doing the programmingassignment.                      Warmup Exercise 4Aside from you, the avatar, what other charactersroam this world?The autonomous people include ben-bitdiddle,alyssa-hacker, course-6-frosh, and lambda-man.dr-evil and mr-bigglesworth are monitors. grendeland registrar are trolls.What sorts of things are around?Spells, blackboard, lovely-trees, flag-pole, ...How is it determined which room each person andthing starts out in?Spells are in chamber-of-stata, everything else israndom2Warmup Exercise 5Create an environment diagram corres ponding to the evaluation of tt (define my-foo (thing ’foo some-location)). Warning: this environment diagram can get out of hand, and we want you to use this exerciseto get a sense of how the system works. So, don’t worry about the value bound to some-location, just drawit as a blob. Similary, don’t worry about showing the object bound to maker. For the bindings associatedwith methods, just leave the actual value blank. Once you have drawn your environment model, draw boxesaround the structures that correspond to each of the superparts of the object created.Solutions are posted at:http://people.csail.mit.edu/ dalleyg/6.001/tutorial09warmup5.pnghttp://people.csail.mit.edu/ dalleyg/6.001/tutorial09warmup5.pdfhttp://people.csail.mit.edu/ dalleyg/6.001/tutorial09warmup5.vsdHippogryphThe hippogryph, living far


View Full Document

MIT 6 001 - Lecture Notes

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?