Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Final Exam Review Fall 2003: Questions on Objects

Questions, comments, answers?

Back to Fall2003 Final Exam Review


1) A class defines the data and behavior of an object, as well as what they know and can do. An instance is an object that belongs to a certain class.
2) Functions may be understood by different classes of objects, but methods are specific to an object. This is why two functions can not have the same name, but two methods can as long as they belong to different objects.
3) Procedural programming is verb-oriented and focuses on defining tasks and their inputs and outputs. Object-oriented programming is noun-oriented and focuses on modeling objects of the world. Functional programming involved layers of functions that can be used to apply other functions and solve a problem with very few lines of code.
4) Polymorphism describes methods that share the same name but are applied to different objects.
5) Alan Kay wanted objects to be similar to cells in that they would be independent and indivisible but interact in standard ways.
For #2, are methods and functions used the same way? Do they look different? How does recursion relate to #3? What are some characteristics that make cells a good model for programming?(#4) Lauren Biddle

To try and answer one of Lauren's questions: We call methods using dot notation: object.method() #12

I am having trouble with the question about biological cells and objects. Some help?

#5 above is pretty good. Certainly more could be said, e.g., about robustness. What doesn't make sense? Mark Guzdial


For #5. If one cell dies the whole system doesn't go down, likewise if one object fails the system shouldn't crash.

  1. 5 Alan Kay had a desire to make software more robust, more maintainable, more scalable. Is that what you're looking for?


I'm not sure I see how #3 has anything to do with Recursion. Could you explain recursion again please?
Sara Jones


Oh yeah, and to answer lauren's question on #4: What are some characteristics that make cells a good model for programming?(#4) Lauren Biddle–>Cells are a good model for programming because all cells have a specific task to perform, and when placed together they all fit well into making a specific organism that can do many tasks. However, a cell can also operate of its own, without the rest of the cells, because it has all that it needs, nucleus, cytoplasm, organelles, etc etc. Much like in good programming, where a programm should have several functions that can operate on their own, but when put together in one big function, they can perform a whole new task. Am I making sense? I'm kinda tired today, hard to explain I guess. Is that ok?


1. What's the difference between an instance and a class?

A class defines a set of instances. Instances are objects that know things and do things. The things
an object knows are considered to be 'instance variables' and the things an object can do are considered to be
'methods'. The slide show example is as follows: The slide show is a class of objects. Each slide is an object.
Each slide knows it's picture and it's sound (these are it's instance variables) and each slide can show itself
(that is one of the slides methods).
Analogically speaking, an instance is to a class as
a slide is to a slide show.

2. How are functions and methods different?
Functions are ways to execute methods. There are many methods defined in JES, more than there are functions. An example of a method is makePicture(), another is pic.show(). To call that method on an object directly,
we would type into the black screen:
 
       >>> pic=makePicture(getMediaPath("barbara.jpg"))
       >>> pic.show()
       


If we wanted to execute these methods using a recipe, we would define the methods as functions. Something like this:
         def show(picture):
           if not picture .__class__==Picture:
              print "show(picture): Input is not a picture"
              raise ValueError
            picture.show()
         


3. How is object-oriented programming different from procedural programming and functional programming?
Functional programming defined functions as data and uses functions as input. The type of functional programming we've been doing in JEs is procedural programming, because we've been defining procedures. Functional programming is good when the problem to be solved is ill-defined. Object-oriented programming can be thought of as 'noun-oriented programming'. Whereas procedural programming works well with broad and difficult problems, the more common noun-oriented programming works well when the problem to be solved is thought of as a domain and all 'nouns' (people, things, etc) within that domain can be defined as objects.

4. What is polymorphism?
Polymorphism is a quality names/words possess in computing. We can use the same word or name to invoke different methods.
For example, show() is a method that works for both slides and pictures. But a picture will just show itself, while a slide
will show itself and play all accompianing music, when executed. In this respect, show() is polymorphic. The word polymorphic is a
self-descriptive term.

5. How did biological cells influence the development of the ideas of objects?
Alan Kay (a jazz guitarist!) used this metaphor. Like cells, (in a human body, for instance), objects (in an object-oriented programming language) can manage complexity, by distributing any given tasks among many objects. They work relatively independently. They support reuse because each object provides services to other objects (like cells working together in different and multiple ways).

(M.H.W.)





Functional programs tend to rely on recursion for looping. Since the functions in a functional program tend to work on very small amounts of data at a time, they lend themselves to recursion easily.

Don't forget other forms of polymorphism we discussed, like setRed() and writeTo().

makePicture() is NOT a method. show() is a method.

Recipes can be made up of methods or functions.

Mark Guzdial


A defined object in object-oriented programming can be applied to any function or procedure by importing the object, like we did import random & stuff like that. Functional programming takes a pre defined function and inputs to that function like we did for the functional recursion. Procedural programming is step by step procedures to define tasks and inputs and outputs to those tasks. I don’t think I am explaining this very well. Can someone pls. explain in very simple terms?

When we were doing import random and import os, we weren't really importing objects. We were importing modules, which are used like objects in the sense of using dot notation, but they don't have any of the characteristics of objects. For example, you can make instances of an object class – you can't make instances of modules. Functional programming is about programming with functions, including functions that take functions as input (like map, reduce, and filter) and recursive functions. Procedural programming is what we've been doing where some of our "functions" didn't take inputs and didn't return anything. Functional programming is always using REAL functions, like in math, that always return something. There's not hard and fast lines between these things – many programs blend all three kinds of programming. Even the programming we were doing with procedures was using objects, so you could say that we've always blended procedural (sometimes called imperative – we're commanding the computer to do things) with object-oriented. But they are different styles and have their distinct strengths and weaknesses. Mark Guzdial

These are some last minute object questions from the lecture. Can someone pls. ans. before clock ticks 8am.

1. What does the domain refer to in the object-oriented programming?
The topic area for the program. If you were building a program to replace Banner, the domain would be class scheduling and student registration. Mark Guzdial
2. Is slide1 an instance of class slide?
Yup. Mark Guzdial
3. The slide show that we created by defining class and slide1 & then running the show function on slide1 doesn't work. Here's what I did:
In the program area, I typed
class slide:
def show(self):
show(self.picture)
blockingPlay(self.sound)
Then in the command area, I did class slide:,slide1 = (),slide1.picture = makePicture(getMediaPath ("barbara.jpg")),slide1.sound = makeSound(getMediaPath("bassoon-c4.wav")), and last slide1.show(). What in the world did I do wrong.
What error did you get? Don't type class slide: in the command area. You just need it in the program area. Mark Guzdial
4. Is encapsulation combing data and behavior of that object, not data?
Combining both data and behavior. Mark Guzdial




Link to this Page