Document not found! Please try again

Lecture 1 - Document Engineering Lab

13 downloads 364 Views 1MB Size Report
Interfaces. Object-Oriented Design ... Cay S. Horstmann. • Out-of-Print. • Second ... Ralph Johnson. John Vlissides. • 'Gang of Four'. The text on design patterns ...
Object-Oriented Programming Dr. Steven Bagley

Dr. Steven Bagley C55 [email protected]

Lectures and Labs

Lectures

Lectures and Labs Monday 12:00 (LT2)

Thursday 17:00

Lectures

Lectures and Labs Monday 12:00 (LT2)

Thursday 17:00 (LT2)

Lectures

Monday 12:00 (LT2)

Thursday 17:00 (LT2)

Labs

Lectures and Labs

Thursday 14:00

Friday 12:00

Lectures

Monday 12:00 (LT2)

Thursday 17:00 (LT2)

Labs

Lectures and Labs

Thursday 14:00

Friday 12:00

Introduction • Writing Programs in an OO-fashion • Application Developers Point-of-View • Technology and Methodology

Objects and Classes

Objects and Classes The Mechanics of Objects

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership Implementing Classes

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership Implementing Classes Interfaces

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership Implementing Classes Interfaces Object-Oriented Design

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership Implementing Classes Interfaces Object-Oriented Design Design Patterns

Objects and Classes The Mechanics of Objects Memory Management and Object-Ownership Implementing Classes Interfaces Object-Oriented Design Design Patterns Inheritance, Polymorphism and Aggregation

Exams • 25% Coursework • Implementing Reference Counting • Designing and implementing a simple OO-system

• 75% exam

! G

Exams

N I N

• 25% Coursework • Implementing Reference Counting • Designing and implementing a simple

R A W OO-system

• 75% exam

G52OBJ • Under new management! • Introduced a new syllabus in 2008 • Exams prior to 2007/08 are not useful! • More details on the exam later…

OO Languages

OO Languages • Numerous OO Languages • OBJ use both C++ and compare with JAVA • Because it is good for you!

OO Languages • Numerous OO Languages • OBJ use both C++ and compare with JAVA • Because it is good for you!

OO Languages • Numerous OO Languages • OBJ use both C++ and compare with JAVA • Because it is good for you!

OO Languages • • •

a v a fJ o se try, u e dus h , t I [ n t m i rg, N u o b o e r a b f s ge] m t . o n i e Numerous OO Languages o r a a l l o p angu el, B m m o l , Int and c g f n , i o n M i t m t B I r m T,and OBJ used both compare with a a lo graC++ M & o a T d r h e A p e e t h m v s ha a fir ly fro Lock I Because for you! ft, as ifiit calis sgood o c icro e p s M

JAVA

OO Languages • • •

. ] e g a u g n l a l a c t i rs ectr out fi l e o e h t t e d s h rte ent a t a v + to sta a m J t r h s + nt a Numerous OO Languages c p C a e e e ing t d d [ u S t h d i s c C d a E e e ] E , th t M e d . & s h e + t t OBJ use both C++ and compare with t A n + r n s a e e tud to C a I st h x e w Ss [T hen d d e n C h a T c s e t i r h Because it is good for you! t e w e s in gram g n e pro

JAVA

OO Languages • Numerous OO Languages • OBJ use both C++ and compare with JAVA • Because it is good for you!

OO Languages • Numerous OO Languages • OBJ use both C++ and compare with JAVA • Because it is good for you! • JAVA is too OO!

Resources •

Practical OO Development in C++ and Java Cay S. Horstmann

• •

Out-of-Print Second hand copies available on Amazon

Resources • Head First

Design Patterns Eric and Elisabeth Freeman

• •

O’Reilly ISBN: 978-0-596-00712-6

Resources •

Design Patterns Erich Gamma Richard Helm Ralph Johnson John Vlissides



‘Gang of Four’ The text on design patterns

Resources Notes • Lecture http://www.eprg.org/G52OBJ/

• PDF notes on C++ also available there

Object-Orientation

Ask audience what comes into their head about it? Ask how old? Simula quote

Objects • OO Programs built from Objects • Objects communicate to solve task • Hard to define • short int — number between ±32768 • long int — number between ±2 31

Objects in EMail system

• What objects would you find in an email system?

Ask the audience Then ask them what characterizes them

Objects • Characterized by: • State • Operations • Identity

Object State • Objects have data • Only altered by the result of operations • Determines the result of operations • Mailbox may accept new messages when empty but not when full

Object Operations • Objects have a set of operations they can perform

• OO Programs ask objects to carry out operations

• Not all objects support all operations

(Can a mailbox solve linear equations?)

Object Identity • State + Operations ≠Object • Objects need identity

Explain we’ll look at how all this is handled...

Object • • •

State Operations Identity

Object • • •

State Operations Identity

Objects • Mother Clanger is not the type of Objects we mean

• Computer representation of her in a game…

• Best to use experience and intuition to find them

Class • Class describes a collection of objects that: • Support the same operations • Support the same possible states • Class definition must define both these

Mailbox Class • Can: • Add a Message • Delete Message • List Messages • etc… Operations imply notion of state e.g. List of messages Current message

Mailbox Class • State not arbitrary e.g: • Messages sorted by arrival time • Objects that conform to a class are called instances of that class

From Problem to Code • This course is about Design and

Implementation in an OO fashion

• Programs originate from the desire to solve a problem

• Could be simple, could be complicated

From Problem to Code • Can break this down into three phases • Analysis • Design • Implementation • This is not a linear-ordering (no waterfalls here!)

From Problem to Code • Implementation experience may lead to a better design

• New requirements mean the project design and implementation change

• OO software generally stands up better to these changes than procedural

Analysis • Problem turned into a precise description • Tasks completely defined • No contradictions • Readable by experts and developers • Reviewable • Testable against reality

Analysis • User manual + Reference Manual • ‘What’ not ‘How’… • Specialist techniques for Large Projects, beyond the scope of the course

Design • Structure the task into classes and class clusters

• Precise definitions of Class • Operations • Relationship to other classes

Design • ‘What’ not ‘How’ • Although our ‘What’s are now more specific

• Look at this in detail

Implementation • Implementing the design in a programming language

• OO lends itself to gradual development • Common to build a rapid prototype • This can then inform the design and analysis phase

OO Design • Goal to break the task into classes • Define functionality of the classes

Email Example •

Consider an email system



Likely to have several Mailboxes



But what can we do with a mailbox?

Mailboxes • What Operations? • Add email to it • View the current email • Delete the current email • Implies state (list of email, current email) • Implies other objects (email)

OO Design Process • Identify the classes • Identify the functionality of these classes • Identify the relationships among these classes

OO Design Process • Goals, not steps • Iterative process • Find some classes • Define functionality • Leads to more classes

OO Design Process • End Result • List of Class Descriptions • Overview of Class Relationships • Foundation for Implementation For each class we explain its purpose, list its operations and describe how it can be composed of other classes.

Finding Classes • Look for nouns in the problem analysis • Tend to be good choices for classes • Others will become apparent

Finding Operations • Verbs tend to point to operations • Each operation should have exactly one

class that is responsible for carrying it out

• Put operations on classes that make sense

Finding Relationships • Three common relationships: • Association or use • Aggregation or containment • Inheritance or specialization

Association • Class uses Objects of another class • Important to minimize coupling

Aggregation • Concrete relationship • Pointers or actual objects • Could be 1:1 or 1:n

Inheritance • is-a relationship • Specializes a class • Add extra operations • Enhance inherited operations

Inheritance • Important to exploit similarities between classes

• Often one class (subclass) is a specialized version of another class (superclass)

• Subclass must be valid whenever the superclass is