This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: O BJECT O RIENTED P ROGRAMMING 11 GEORGE WANG email@example.com Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 12, 2010 1 Introduction Up until now, weve been dealing with functional programming, where theres no changing of data. Weve always been just concerned with the input/output pairing of a function. For the next week and a half, well be changing that viewpoint. This entire week is about object oriented programming. Today and tomorrow, well discuss an Object Ori- ented framework. Later this week, well examine how this framework is actually implemented in Scheme. What well now be thinking of, instead of a kind of mathematical view of computing, is well be moving to a view of having many agents acting more or less independently inside a computer. In Functional Pro- gramming, weve dealt with one large program created by composing various smaller programs together. In this next view, a view of Object Oriented Programming, the idea is that there are multiple things, each of which is designed to specialize at a certain task. To have this happen, we need three key things: Message Passing - Enables cooperation and collaboration between objects. Local State - An object can remember things about its past history Inheritance - Enables specialization so that objects can fulfill niche roles without sacrificing the bigger pictures. 2 Message Passing The first, message passing, is something weve already seen last week. As a reminder, message passing is the paradigm where instead of having functions that do things, our data is capable of handling the operations we need. Instead of operating on data, we tell the data what to do, and it is able to do it on its own. 1 Lets look at a program to do the same message passing things we did last week: ;;;;; In file cs61a/lectures/3.0/demo.scm (define-class (square side) (method (area) ( * side side)) (method (perimeter) ( * 4 side)) ) > (define sq (instantiate square 5))...
View Full Document