Docsity

Interfaces and Objects - Analysis and Design | CSCI 6448, Study notes of Computer Science

Toggle sidebar
bg1
Lecture 13: Interfaces and Objects
Kenneth M. Anderson
Object-Oriented Analysis and Design
CSCI 6448 - Spring Semester, 2001
February 27, 2001 © Kenneth M. Anderson, 2001 2
Goals for this Lecture
• Introduce
– Interfaces
– Objects
• Examine their associated UML Notations
February 27, 2001 © Kenneth M. Anderson, 2001 3
Interfaces
• An interface is a collection of operations
(not data) that specifies a particular service
of a class or a component
– For instance, lists, queues, stacks, and trees
typically provide an Iterator interface that
allows other classes to cycle through their
elements
February 27, 2001 © Kenneth M. Anderson, 2001 4
UML Notation
• The most simple notation for an interface is
a labeled circle
Iterator
Interface names can be grouped using
packages
Java::Collection::Iterator
pf3
pf4

Partial preview of the text

Download Interfaces and Objects - Analysis and Design | CSCI 6448 and more Study notes Computer Science in PDF only on Docsity!

Lecture 13: Interfaces and Objects

Kenneth M. Anderson

Object-Oriented Analysis and Design

CSCI 6448 - Spring Semester, 2001

February 27, 2001

© Kenneth M. Anderson, 2001

Goals for this Lecture

• Introduce

  • Interfaces– Objects

• Examine their associated UML Notations

February 27, 2001

© Kenneth M. Anderson, 2001

3

Interfaces

• An interface is a collection of operations

(not data) that specifies a particular serviceof a class or a component

  • For instance, lists, queues, stacks, and trees

typically provide an Iterator interface thatallows other classes to cycle through theirelements

February 27, 2001

© Kenneth M. Anderson, 2001

UML Notation

• The most simple notation for an interface is

a labeled circle

Iterator

Interface names can be grouped usingpackages

Java::Collection::Iterator

February 27, 2001

© Kenneth M. Anderson, 2001

5

UML Notation

• However, a full class diagram can be used

to specify the particular operationsassociated with an interface

«interface»

Iterator

init() next() more()

No attributes allowed!

February 27, 2001

© Kenneth M. Anderson, 2001

How interfaces are used

You cannot instantiate an instance of an interface,instead other classes (and thus their objects)choose to implement certain interfaces

  • An interface can act as a type, so you can declare

variables that have, for instance, the Iterator type

  • This allows you to point at a class who implements the

Iterator interface without knowing (or caring) aboutwhat its actual type is

February 27, 2001

© Kenneth M. Anderson, 2001

7

UML Notation

• To indicate that a class implements a

particular interface, use the “lollipop”notation

• This is also called “realization”

Stack

The lollipop

Iterator

February 27, 2001

© Kenneth M. Anderson, 2001

UML Notation, continued

• When drawing an interface using a class

diagram, realization is shown using thefollowing notation

«interface»

Iterator

init() next() more()

Stack

The fact thatrealization hastwo notationsis, in my opinion,unfortunate.

February 27, 2001

© Kenneth M. Anderson, 2001

13

Objects

• Objects are instances of classes

  • an object can be named or unnamed

Ken’s Print Queue: Queue

: Photo

A named object

An unnamed object

February 27, 2001

© Kenneth M. Anderson, 2001

Multiobjects

• If you need to model a collection of

anonymous objects (such as a stack orqueue), you can use the multiobject notation

:Queue

:Queue

This represents thecollection object andall of its individualinstances

February 27, 2001

© Kenneth M. Anderson, 2001

15

Orphan Instances

• In some situations, you may need to model

an object whose type is unknown

  • This can occur in practice when dynamically

loading an object into memory

  • Use the orphan notation to indicate such an

object

plugin :

If you later discover the typeof an orphan instance, youcan transform it to a namedinstance using the «become»stereotype (not yet covered)

February 27, 2001

© Kenneth M. Anderson, 2001

Active Objects

• Finally, you can indicate that an object has

its own flow of control (e.g. it’s a Threadobject) using the following notation

n: notifier