This preview shows page 1-2-3-4-5-6-7-8-58-59-60-61-62-63-64-65-66-118-119-120-121-122-123-124-125 out of 125 pages.
61A Lecture 14Friday, September 30Friday, September 30, 2011The Story So Far About Data2Friday, September 30, 2011The Story So Far About DataData abstraction: Enforce a separation between how data values are represented and how they are used.2Friday, September 30, 2011The Story So Far About DataData abstraction: Enforce a separation between how data values are represented and how they are used.Abstract data types: A representation of a data type is valid if it satisfies certain behavior conditions. 2Friday, September 30, 2011The Story So Far About DataData abstraction: Enforce a separation between how data values are represented and how they are used.Abstract data types: A representation of a data type is valid if it satisfies certain behavior conditions. Message passing: We can organize large programs by building components that relate to each other by passing messages.2Friday, September 30, 2011The Story So Far About DataData abstraction: Enforce a separation between how data values are represented and how they are used.Abstract data types: A representation of a data type is valid if it satisfies certain behavior conditions. Message passing: We can organize large programs by building components that relate to each other by passing messages.Dispatch functions/dictionaries: A single object can include many different (but related) behaviors that all manipulatethe same local state.2Friday, September 30, 2011The Story So Far About DataData abstraction: Enforce a separation between how data values are represented and how they are used.Abstract data types: A representation of a data type is valid if it satisfies certain behavior conditions. Message passing: We can organize large programs by building components that relate to each other by passing messages.Dispatch functions/dictionaries: A single object can include many different (but related) behaviors that all manipulatethe same local state.2(All of these techniques can be implemented using only functions and assignment.)Friday, September 30, 2011Object-Oriented Programming3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behavior3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state•Each object has its own local state.3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state•Each object has its own local state.•Each object also knows how to manage its own local state, based on the messages it receives.3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state•Each object has its own local state.•Each object also knows how to manage its own local state, based on the messages it receives.•Several objects may all be instances of a common type.3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state•Each object has its own local state.•Each object also knows how to manage its own local state, based on the messages it receives.•Several objects may all be instances of a common type.•Different types may relate to each other as well.3Friday, September 30, 2011Object-Oriented ProgrammingA method for organizing modular programs•Abstraction barriers•Message passing•Bundling together information and related behaviorA metaphor for computation using distributed state•Each object has its own local state.•Each object also knows how to manage its own local state, based on the messages it receives.•Several objects may all be instances of a common type.•Different types may relate to each other as well.Specialized syntax & vocabulary to support this metaphor3Friday, September 30, 2011Classes4Friday, September 30, 2011ClassesA class serves as a template for its instances.4Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All bank accounts have a balance and an account holder; the Account class should add those attributes to each newly created instance.Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All bank accounts have a balance and an account holder; the Account class should add those attributes to each newly created instance.>>> a = Account('Jim')Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All bank accounts have a balance and an account holder; the Account class should add those attributes to each newly created instance.>>> a = Account('Jim')>>> a.holder'Jim'Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All bank accounts have a balance and an account holder; the Account class should add those attributes to each newly created instance.>>> a = Account('Jim')>>> a.holder'Jim'>>> a.balance0Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All bank accounts have a balance and an account holder; the Account class should add those attributes to each newly created instance.Idea: All bank accounts should have "withdraw" and "deposit" behaviors that all work in the same way.>>> a = Account('Jim')>>> a.holder'Jim'>>> a.balance0Friday, September 30, 2011ClassesA class serves as a template for its instances.4Idea: All
View Full Document