object oriented programming and design l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Object-Oriented Programming and Design PowerPoint Presentation
Download Presentation
Object-Oriented Programming and Design

Loading in 2 Seconds...

play fullscreen
1 / 49

Object-Oriented Programming and Design - PowerPoint PPT Presentation


  • 233 Views
  • Uploaded on

Object-Oriented Programming and Design. Ralph Johnson johnson@cs.uiuc.edu. Goals: to learn. Principles Patterns Practices “Object think” Design for reuse. History of Objects. Simula’67 Smalltalk 72,74,76,78,80 1985 C++ (Objective C, Object Pascal) 1986 OOPSLA 1990 COM, CORBA

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Object-Oriented Programming and Design' - ovid


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
object oriented programming and design
Object-Oriented Programming and Design

Ralph Johnson johnson@cs.uiuc.edu

Object-oriented programming and design

goals to learn
Goals: to learn
  • Principles
  • Patterns
  • Practices
  • “Object think”
  • Design for reuse

Object-oriented programming and design

history of objects
History of Objects
  • Simula’67
  • Smalltalk 72,74,76,78,80
  • 1985 C++ (Objective C, Object Pascal)
  • 1986 OOPSLA
  • 1990 COM, CORBA
  • 1994 Design Patterns
  • 1995 Java
  • 2001 .NET

Object-oriented programming and design

design principles
Design Principles
  • Encapsulate what varies
  • Code to an interace rather than to an implementation
  • Open-closed Principle: Classes should be open to extension and closed to modification
  • Don’t Repeat Yourself (DRY)
  • Single Responsibility Principle
  • Liskov Substitution Principle: Subtypes must be substitutable for their base types

Object-oriented programming and design

smalltalk
Smalltalk
  • Pure object-oriented language
  • Live objects
  • Readable library
  • Influencial, unknown
  • Fun!

Object-oriented programming and design

from smalltalk
From Smalltalk
  • WIMP - Windows, Mice, Pointing
  • Model/View/Controller
  • Browsers
  • CRC cards
  • eXtreme Programming
  • Automated refactoring tools

Object-oriented programming and design

before objects
Before objects

Computer system consists of data and programs.

Programs manipulate data.

Programs organized by

  • functional decomposition
  • dataflow
  • modules

Object-oriented programming and design

object paradigm
Object Paradigm

Computer system consists of a set of objects.

Objects are responsible for knowing and doing certain things.

Objects collaborate to carry out their responsibilities.

Programs organized by classes, inheritance hierarchies and subsystems

Object-oriented programming and design

what is an object anyway
What is an object, anyway?

Mystical view

Computing systems are made up of objects that communicate only by sending messages between each other. All computation is message sending.

Object-oriented programming and design

what is an object anyway10
What is an object, anyway?

Scandinavian view

A program is a simulation. Each entity in the system being simulated is represented by an entity in the program.

Object-oriented programming and design

what is an object anyway11
What is an object, anyway?

Programming language view

An object-oriented system is characterized by

• data abstraction

• inheritance

• polymorphism by late-binding of procedure calls

Object-oriented programming and design

heart of object oriented programming
Heart of Object-Oriented Programming

Don't make a new language, extend your old one.

Objects should be abstractions of problem domain.

Object-oriented programming and design

modeling
Modeling

All phases of software life-cycle are modeling

• analysis - modeling of problem

• design - modeling of solution

• implementation - making model run on a computer

• maintenance - fixing/extending your model

Object-oriented programming and design

assumption about modeling
Assumption about Modeling

Basing system design on structure of problem makes system

• more reusable

• more extensible

Object-oriented programming and design

modeling15
Modeling

Claim: people model the world with "objects"

• objects

• classes

• relationships between objects

• relationships between classes

Object-oriented programming and design

modeling16
Modeling

Advantages of object-oriented software development

• more natural - matches the way people think

• single notation - makes it easy to move between software phases

Object-oriented programming and design

objects and relationships
Objects and Relationships

John is Mary's father. Mary is John's daughter.

Bob is Mary's dog. Mary is Bob's owner.

Ann is John's employer. John is Ann's employee.

Object-oriented programming and design

objects and attributes
Objects and Attributes

John's name is "John Patrick O'Brian".

John's age is 27.

John's address is 987 N. Oak St, Champaign IL 61820

What about John's job? John's wife?

What is an attribute, and what is a relationship?

Object-oriented programming and design

objects and behavior
Objects and Behavior

John goes on a trip.

John makes reservations.

John buys tickets.

John travels by airplane.

John checks into hotel.

Object-oriented programming and design

what really is an object
What Really is an Object?

Reservation -- a promise to give service to a customer

Ticket -- proof that customer has paid for service in advance

Flight

Payment -- an event (transaction?) in which money is exchanged

Object-oriented programming and design

what really is an object21
What Really is an Object?

Anything we can talk about can be an object, including relationships ("the husband of the first party", "first-born son").

What are we trying to model?

Models should be as simple as possible, but no simpler.

Object-oriented programming and design

classification
Classification

We naturally put objects into classes that have similar characteristics.

• John is a man.

• Mary is a woman.

• Bob is a dog.

• All women are people.

• All people are mammals.

Mammals

Dogs

People

Women

Men

Bob

Mary

John

Object-oriented programming and design

classification23
Classification

• John is an employee.

• John is a father.

• John is a sky-diver.

• John is under 30.

Is John an instance of Employee, Father, Sky-diver, and Under30?

Object-oriented programming and design

summary
Summary

Objects

• have identity

• have attributes

• have behavior

• have relationships with other objects

Object-oriented programming and design

summary25
Summary

Classes

• describes the attributes, behavior, and relationships of a set of objects

• subclasses/superclasses form graph of generalizations

Object-oriented programming and design

the class
The class
  • First month is Smalltalk
  • Homework, often several per week
  • Second half of the semester is group project
  • Put your name on the wiki at http://swiki.cs.uiuc.edu/cs598rej
  • Download Squeak from squeak.org

Object-oriented programming and design

smalltalk in a nutshell

Smalltalk in a Nutshell

Objects & classes

Messages & methods

Inheritance & metaclasses

Object-oriented programming and design

smalltalk everything is an object
Smalltalk: Everything is an Object
  • Application objects: customer, inventory
  • GUI objects: button, text editor
  • Foundation: string, set, numbers, booleans
  • Tools: browser, debugger, compiler, GUI builder
  • Language implementation: class, method, context,

Object-oriented programming and design

communicating with an object
Communicating with an Object

All computation is done by objects.

The only way to interact with an object is to "send a message" to it.

Smalltalk has three kinds of syntax for sending a message.

All messages have same implementation.

Object-oriented programming and design

three kinds of message syntax
Three Kinds of Message Syntax

Unary messages

aSalaryChange date

Keyword messages

earned at: date add: money

Binary messages

(worked - 40) max: 0

Object-oriented programming and design

sending a message
Sending a Message

Object responds to message by looking in its class for a method with the same selector.

If it doesn't find the method, it looks in its superclass.

Repeat until it finds the method. If it never does, there is an error.

Object-oriented programming and design

smalltalk in a nutshell32
Smalltalk in a nutshell
  • Classes have methods and variables.
  • Methods are a sequence of messages, assignments, returns.
  • Variables, literals, psuedovariables
  • Blocks
  • Metaclasses - classes have classes

Object-oriented programming and design

message lookup and inheritance
Message Lookup and Inheritance

EmployeeTransaction has subclasses Paycheck, SalaryChange, and Timecard.

EmployeeTransaction defines the instance variable date and the method:

date

^date

Object-oriented programming and design

slide34

EmployeeTransaction

date

check1

07/09/95

Paycheck

aPaycheck date

smalltalk expression syntax
Smalltalk Expression Syntax

Literals

3.675, 14, 'hello', #weight, $d,

#( #foo 'bar' 92)

Assignments and variables

v := v + 1

Messages

Object-oriented programming and design

smalltalk expression syntax36
Smalltalk Expression Syntax

Sequences. Blocks.

x < y ifTrue: [z := x] ifFalse: [z := y].

paychecks do: [:each | each post]

Cascades

aSet add: #blue; add: #red

Object-oriented programming and design

smalltalk method syntax
Smalltalk Method Syntax

Returns

^socialSecurity + federalTaxes + stateTaxes

Object-oriented programming and design

variables in smalltalk
Variables in Smalltalk
  • blockArguments and temporaries
  • methodArguments and temporaries
  • instanceVariables

Can be accessed only by the object's methods.

  • Globals, class variables

Any method in the scope can access it

Variable is object of class Association

Object-oriented programming and design

using variables
Using Variables

printOnCheckStream: aStream

aStream cr; cr.

aStream next: 40 put: (Character space).

DateFormat print: date on: aStream.

aStream cr.

...

Object-oriented programming and design

more variables
More variables

test

"PayrollSystem test"

| payroll day1 ralph |

day1 := Date newDay: 5 year: 1996.

payroll := self new.

ralph := Employee new name:

'Ralph Johnson'.

Object-oriented programming and design

continued
(continued)

ralph changeSalaryFor: day1 to: 20.

payroll addEmployee: ralph.

self

employee: ralph

hours: self aLittleOvertime

starting: day1.

^payroll

Object-oriented programming and design

initializing an object
Initializing an Object

Every object needs to be initialized. Uninitialized variables are nil.

The initialization method often defines the type of a variable.

Two methods: one class and one instance.

Object-oriented programming and design

class methods
Class Methods

Class is an object. It can have methods, too.

For class Date class

newDay: dayInteger year: yearInteger

^self new day: dayInteger year: yearInteger

Object-oriented programming and design

instance initializing method
Instance initializing method

For class Date

day: dayInteger year: yearInteger

day := dayInteger.

year := yearInteger

Object-oriented programming and design

creating a date
Creating a Date

Date newDay: 3 year: 1995

Date new day: 3 year: 1995

day

day: 3 year: 1995

year

3

1995

Object-oriented programming and design

complete smalltalk
Complete Smalltalk

Expressions (method definition)

message, assignment, sequence, block, return

Variables, literals

Classes, inheritance

Class methods / instance methods

Pseudovariables

nil, true, false

self, super, thisContext

Object-oriented programming and design

smalltalk the language is trivial
Smalltalk (the language) is trivial

Complexity is class library.

New language extensions fit in as well as numbers and control structures.

Language extension => core language is trivial

Object-oriented programming and design

implications
Implications

class library = language extension

=>

must know class library

must standardize class library

merging class libraries is like merging language extensions

hard to make class libraries

Object-oriented programming and design

applications
Applications
  • No programs, just objects
  • No “main” routine
  • Most applications create new classes, reuse a lot of existing ones

Object-oriented programming and design