Computer Science 209 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Computer Science 209

Description:

The set of public methods of a class ... Interfaces are the glue that holds a software ... Don't force users to jump through hoops to perform simple tasks ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 18
Provided by: KenLa2
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 209


1
Computer Science 209
  • The Criteria of a Good Interface

2
What Is an Interface?
  • The set of public methods of a class
  • Well, not exactly, because a class can implement
    several interfaces
  • Better A set of methods that supports a single
    concept or purpose

3
The Importance of Interfaces
  • Interfaces are the glue that holds a software
    system together. They allow software components
    to
  • be developed independently
  • be reused in other applications
  • have several different implementations

4
The Importance of Interfaces
  • Interfaces separate the concerns of users and
    implementers
  • If users and implementers obey this contract, the
    rest is easy
  • We should strive to program to interfaces, not
    implementations

5
Criteria for a Good Interface
  • Cohesion
  • Completeness
  • Convenience
  • Carity
  • Consistency

6
Cohesion
  • A class is an abstraction of a single concept and
    should fulfill a coherent purpose
  • Methods in the interface should all deal with
    that purpose
  • Irrelevant methods split into another class

7
Completeness
  • Provide all of the methods required to serve the
    classs purpose
  • Dont leave out essential methods

8
Convenience
  • Make common tasks easy to perform
  • Dont force users to jump through hoops to
    perform simple tasks
  • Examples methods to examine the number of books
    checked out by a patron and the current status of
    a book

9
Clarity
  • Methods should have behavior and results that are
    simple to describe and understand
  • Complex behavior should be split into two or more
    methods

10
Consistency
  • Use conventional method names, parameters, return
    types, and behavior wherever possible
  • Examples equals, toString, and compareTo

11
Operations for Patron
Operations Create a Patron Examine the
name Examine the password Examine the
number of books checked out Increment the
number of books checked out Decrement the
number of books checked out Compare for
equality Return a string representation
Coherent? Complete? Convenient? Clear?

12
Methods for Patron
Methods public Patron(String, String)
public String getName() public String
getPassword() public int getBooksOut()
public void incBooksOut() public void
decBooksOut() public boolean equals(Object
other) public String toString()
Consistent?
13
Operations for Book
Operations Create a Book Examine the title
Examine the author Examine the current
borrower Examine the current status (checked
out or not) Borrow for a given patron
Return for a given patron Compare for
equality Return a string representation
Coherent? Complete? Convenient? Clear?

14
Methods for Book
Methods public Book(String, String) public
String getTitle() public String getAuthor()
public boolean checkedOut() public Patron
getBorrower() public String borrowBook(Patron
p) public String returnBook(Patron p)
public String toString()
Consistent?
15
The Library
Library

Book
0..3
0..1

Patron
PatronQueue


16
Operations for Library
Operations Create a Library Add a patron
Remove a patron Add a book Remove a book
Borrow a book for a given patron Return a book
for a given patron Return a string
representation
Coherent? Complete? Convenient? Clear?

17
Methods for Library
Methods public Library() public String
add(Patron p) public boolean remove(Patron p)
public String add(Book b) public boolean
remove(Book b) public String borrowBook(String
title, String patronName,
String password) public String
returnBook(String title, String patronName,
String password) public
String toString()
Consistent?
Write a Comment
User Comments (0)
About PowerShow.com