33design-35purple

33design-35purple - Object Oriented Programming 3.3...

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

View Full Document Right Arrow Icon
3.3 Designing Data Types Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · * * 2 Object Oriented Programming Procedural programming. [verb-oriented] ! Tell the computer to do this. ! Tell the computer to do that. Alan Kay's philosophy. Software is a simulation of the real world. ! We know (approximately) how the real world works. ! Design software to model the real world. Objected oriented programming (OOP). [noun-oriented] ! Programming paradigm based on data types. ! Identify things that are part of the problem domain or solution. ! Things in the world know things: instance variables. ! Things in the world do things: methods. 3 Alan Kay Alan Kay. [Xerox PARC 1970s] ! Invented Smalltalk programming language. ! Conceived Dynabook portable computer. ! Ideas led to: laptop, modern GUI, OOP. Alan Kay 2003 Turing Award "The computer revolution hasn't started yet." "The best way to predict the future is to invent it." "If you don't fail at least 90 percent of the time, you're not aiming high enough." 4 Encapsulation Bond. What's your escape route? Saunders. Sorry old man. Section 26 paragraph 5, that information is on a need-to-know basis only. I'm sure you'll understand.
Background image of page 1

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

View Full DocumentRight Arrow Icon
5 Encapsulation Data type. Set of values and operations on those values. Ex. int , String , Complex , Vector , Document , GuitarString , Tour , … Encapsulated data type. Hide internal representation of data type. Separate implementation from design specification. ! Class provides data representation and code for operations. ! Client uses data type as black box. ! API specifies contract between client and class. 6 Intuition Client API - volume - change channel - adjust picture - decode NTSC signal Implementation - cathode ray tube - electron gun - Sony Wega 36XBR250 - 216 pounds Implementation and client need to agree on API ahead of time. client needs to know how to use API implementation needs to know what API to implement 7 Intuition API - volume - change channel - adjust picture - decode NTSC signal Implementation - gas plasma monitor - Samsung FPT-6374 - wall mountable - 4 inches deep Can substitute better implementation without changing the client. Client client needs to know how to use API implementation needs to know what API to implement 8 Counter Data Type Counter. Data type to count electronic votes. Legal Java client. Oops. Al Gore receives -16,022 votes in Volusia County, Florida. public class Counter { int count ; public final String name ; public Counter ( String id ) { name = id ; } public void increment () { count ++; } public int value () { return count ; } } Counter c = new Counter ("Volusia County"); c . count = -16022 ;
Background image of page 2
9 Counter. Encapsulated data type to count electronic votes. Does not compile. Benefit. Can guarantee that each data type value remains in a consistent state. public class Counter { int count ; public final String name ; public Counter ( String id ) { name = id ; } public void increment () { count ++; } public int value () { return count ; } } Counter Data Type Counter c = new Counter ("Volusia County"); c . count = -16022 ; 10 Changing Internal Representation Encapsulation.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

33design-35purple - Object Oriented Programming 3.3...

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

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