MINS 116 - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

MINS 116

Description:

Interface Concepts. Interface Hierarchy 'Design by Contract' UML Constructs ... Concepts ... directly support this important concepts are defined by the ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 28
Provided by: Jim455
Category:
Tags: mins

less

Transcript and Presenter's Notes

Title: MINS 116


1
MINS 116
  • Spring 2000
  • Interfaces

2
Interface Presentation Objectives
  • Interface Concepts
  • Interface Hierarchy
  • Design by Contract
  • UML Constructs
  • Java Interface Constructs

3
Concepts
  • Q What is an interface (in general)?
  • (Hint Think about the interfaces you deal with
    in your daily life
  • Give some examples )

4
Concepts
  • Everything we encounter while existing has an
    interface.
  • People we encounter have interfaces.
  • What are some of these?
  • Interfaces are a necessary part of daily
    existence.
  • Remember the existentialists argument regarding
    the Brain in a Vat.

5
Concepts
  • The Real World is composed of very well defined
    interfaces.
  • These interfaces are well defined because of
    their physical nature (e.g. your interface with a
    tree or sidewalk can be easily explained).
  • What are some poorly defined interfaces we deal
    with daily?

6
Concepts
  • An interface is a point of contact with something
    allowing us to gain better understanding of
  • What the thing is.
  • What it does.
  • How it behaves.
  • Given a certain stimulus, what kind of response
    do we get back?

7
Concepts
  • Q What is an interface in terms of computer
    based technology?

8
Concepts
  • There are direct and indirect interfaces
    associated with computer based technology as
    related to a computer user.
  • Direct interface are easy for us to see.
  • Indirect indirect interfaces live somewhere
    behind the scenes.

9
Interface Hierarchy
  • Interface Pyramid

GUI - High User Visibility Low Code
Volume UI - Medium User Visibility
Medium Code Volume I - Low or no User
Visibility High Code Volume
10
Interface Hierarchy
  • What we, as direct computer users (e.g. users of
    browsers, computer screens, etc.) see most of is
    the GUI.
  • What we, as indirect computer users (e.g. placing
    a phone call, using a vending machine, etc.)
    interface with, possibly without seeing, is the
    UI.
  • What goes on behind the scenes, without user
    knowledge, is the I.

11
Interface Hierarchy
  • The largest volume of code written involves the
    I.
  • The code given least attention and testing
    involves the I.
  • The hardest code to debug and correct involves
    the I.
  • The code with the longest reaching effects is
    involves the I.

12
Interface Hierarchy
  • Software Crisis
  • The code used most often, has the largest volume,
    is hardest to pin down, tested least, the most
    difficult to debug, hardest to correct, and has
    farthest reaching effects.

13
Interface Hierarchy
  • Crisis? What Crisis?

We can alleviate some of the problems inherent in
software production by employing Design by
Contract, introduced by Bertrand Meyer.
14
Design by Contract
  • An interface can be well defined by specifying
  • 1) Preconditions - What is the necessary state of
    the system prior to entering the interface.
  • 2) Postconditions - What is the necessary state
    of the system upon interface exit.
  • 3) Invariant - What is the necessary stable state
    of the system throughout the lifetime of the
    system execution.

15
Design by Contract
  • By defining preconditions, postconditions, and
    invariants related to an interface, we are
    defining, to any potential user of the interface
  • 1) What we expect of them before the use the
    interface.
  • 2) What they should expect as a result of using
    the interface.
  • 3) What the steady state of the system is with
    respect the the interface.

16
UML Constructs
  • In UML, an interface is just a class which has
    been stereotyped as an interface.
  • An interface should only have behavior (methods)
    defined. An interface can not have state
    (attributes) defined.

Stereotype
Class Name
No Attributes
Methods
17
UML Constructs
  • After the interface is properly defined, classes
    can be defined which will implement the
    interface.

Customer defines the interface. eCustomer and
Store Customer are both classes in which the
implementation code must provide the logic to
carry out the interface operation.
Interface Class
Implements symbol
Implementing Classes
18
Java Interface Constructs
  • Java constructs which directly support this
    important concepts are defined by the keywords
  • interface - provide an interface definition.
  • implements - provide an implementation of an
    interface definition.

19
Java Interface Constructs
  • For the Customer example .java code
  • //
  • // public class ICustomer is an example
  • // .java interface.
  • public interface ICustomer
  • // orderItem - place an item into a customers
  • // order area.
  • //
  • // return value The inventory item ID of the
    ordered
  • // item of order was successful.
    -1 if the
  • // item has been back ordered.
  • Next slide..

20
Java Interface Constructs
  • //
  • // precondition The customer must have
    defined an order area.
  • //
  • // postcondition If the item was successfully
    ordered, the
  • // item number will be removed
    from the inventory
  • // list.
  • //
  • // invariant The maximum number of
    ordered items per customer
  • // is set to MAX_CUSTITEMS.
  • //
  • public abstract int orderItem( int itemID )
  • ....
  • Also define for receiveInvoice() and
    payInvoice()
  • ....

21
Java Interface Constructs
  • By having an interface definition with
    preconditions, postconditions, and invariants
    defined, we have taken all the guessing work out
    of the actual implementation.
  • now, lets take a quick look at an
    implementation

22
Java Interface Constructs
  • //
  • // public class eCustomer is an example
  • // of an implementation of the .java interface.
  • // ICustomer.
  • public class eCustomer implements ICustomer
  • // orderItem - place an item into a customers
  • // order area.
  • //
  • // return value The inventory item ID of the
    ordered
  • // item of order was successful.
    -1 if the
  • // item has been back ordered.
  • //
  • next slide...

23
Java Interface Constructs
  • // precondition The customer must have
    defined an order area.
  • //
  • // postcondition If the item was successfully
    ordered, the
  • // item number will be removed
    from the inventory
  • // list.
  • //
  • // invariant The maximum number of
    ordered items per customer
  • // is set to MAX_CUSTITEMS.
  • //
  • public int orderItem( int itemID )
  • // Check for invariant violation. Return a
    failure
  • // if a violation occurred.
  • ...
  • // Check the precondition. Throw an
    excpetion
  • // if not met.
  • next slide...

24
Java Interface Constructs
  • // Perform the required logic.
  • ...
  • // Check the postcondition. Throw an
    exception
  • // if not met.
  • ....
  • etc.
  • ....

25
Concluding Remarks
  • Interfaces apply to all areas of software
    development, not just the GUI.
  • If we can define the general interface well (the
    I in this presentation), we can define all
    aspects of software well.
  • Design by Contract provides some good
    guidelines for interface (I) design and
    definition.

26
Concluding Remarks
  • Java directly supports the concept of interface
    definition through the use of interface and
    implements.
  • Preconditions, postconditions, and invariants
    should be checked in the implementation code.

27
and now...
  • Enough about general software interfaces.
  • On to GUI design..
  • Last Words - The best interfaces are the ones we
    dont even know we are using.
Write a Comment
User Comments (0)
About PowerShow.com