Академический Документы
Профессиональный Документы
Культура Документы
Oriented Design
OO Requirements
► Identify objects that are necessary for
the context of a desired software
application
► A class is the data AND the code!
► Methods affect change upon the data
MSTU4031 2
Design Example
► Your are given the following request:
MSTU4031 3
Requirements Analysis
<<identify nouns>>
For the first phase of the library system your are to
collect information about books. What information
or attributes describe a book? Let’s list them:
MSTU4031 4
What is a class?
Object – An instance of a class
Class – The program; the code. The data, and code to act on that data
Data
Operations
MSTU4031 5
Analysis Outcome
MSTU4031 6
Model
Library Book
… title : String
author: String
…
MSTU4031 7
► public class BookMain
► { // open BookMain class
► /**
► Tests the methods of the Book class
► @param args not used
► */
► public static void main (String[] args)
► …
► …
Object reference Create a ‘new’ one
► …
MSTU4031 8
► public class BookMain
► { // open BookMain class
► /**
► Tests the methods of the Book class
► @param args not used
► */
► public static void main (String[] args)
MSTU4031 9
►
public class Book
{
/**
Constructs the initial book without a title, author, or page numbers.
Default constructor, entry way into the program
*/
public Book ()
{
Constructor Construtor’s Parameters
}
/**
Constructs the initial book with a title, author, and page numbers.
@param inputtitle
@param inputauthor
@param inputpages
*/
public Book (String inputtitle, int inputpages, String inputauthor)
{
booktitle = inputtitle;
bookpages = inputpages;
bookauthor = inputauthor;
} Parameter passed to Method
/**
Sets book title
@param inputtitle the title of the book
*/
public void setBookTitle (String inputtitle)
{
Return Type booktitle = inputtitle;
} MSTU4031 10
Method Name Local Private Variable
References
► JDK online documentation.
► Java Forums
MSTU4031 11