Designing a Java Program Principles of Software Engineering



































- Slides: 35

Designing a Java Program Principles of Software Engineering INFSY 535

Systems � Small systems � Larger systems

l. Planning, design, and testing 1. Understand the program requirement-what Analysis I/O is critical 3. Write and test each part (unit testing) implementation 2. Specify the solution-how Model/design (UML comes into play) 4. Maintenance ldeployment

l. The Waterfall Model what how Write

l. The Spiral Model : deals with errors from previous phase (Boehm)

Rational Unified Process • Development process methodology by the inventors of UML

l. Extreme • Programming Focuses on best practices • • Realistic planning Small releases Metaphor Simplicity Testing Refactoring Pair programming Collective ownership Continuous integration 40 -hour week on-site customer coding standards

l. Levels of Abstraction: Black Box • Interaction of a black box with outside world is well-defined • Encapsulation l. Big Java by Cay Horstmann l. Copyright © 2008 by John Wiley & Sons. All rights reserved.

Java Class Concept Encapsulation ◦ Blackbox concept methods called Interface Data and method(s) Hidden details class Effect(s)

A Class Example (from Chapter 3) l Behavior of bank account (abstraction): • deposit money • withdraw money • get balance

l. Specifying the public Interface of a Class l. Methods of Bank. Account class: • deposit withdraw • get. Balance • Support method calls such as the following: harrys. Checking. deposit(2000); harrys. Checking. withdraw(500); System. out. println(harrys. Checking. get. Balance());

Public Interface of a Class or Method Definition access specifier (such as public) lreturn type (such as String or void) lmethod name (such as deposit) l. Parameters list (double amount, double deposit) l method body { } l

Method Definition Format access. Specifier return. Type method. Name(parameter. Type parameter. Name, . . . ) { method body }

Method Definition Example: public void deposit(double amount) {. . . }

Public Interface of a Class: Constructor Definition public Bank. Account() { // body--filled in later

l. Javadoc Method Summary

UML Class Diagrams Model/design/represent the solution? Show class relationships

Components of the UML �Class � Object Diagram � Use Case Diagram � State Diagram � Sequence Diagram � Activity Diagram � Collaboration Diagram � Component Diagram � Deployment Diagram

UML: Universal Modeling Language � Rectangles � Three sections: ◦ Class/object name ◦ Class attributes (data) ◦ Operations (methods) � Arrows that indicates the relationship

Class Diagram with Variables and Methods Class Name Visibility: private - Attributes/ characteristics: variables public + (chapter 3) Methods/capabilities

Using VISIO 2007 to Produce UML Diagrams �Click on VISIO �Select the Software Category

Visio Lab � Visio Tutorial

§Inheritance §Aggregation §Dependency l. Relationships Between Classes

UML Class Diagrams Preparation: ◦ Verbally describe the situation (what) ◦ (How) �Find objects (methods) that will be part of model �Describe properties of the objects �Establish relations between the objects �Place the objects in groups

Java facilitates working with Objects Terminology: l Objects are abstractions l Objects are manipulated by classes • May be 1 or many class instances of any particular class/object. • Each instance is instantiated.

l. UML Relationship Symbols Line Style Arrow Tip Inheritance-is-a Solid Triangle Interface Implementation Dotted Triangle Aggregation-has-a Solid Diamond Dependency Dotted Open Relationship § Symbol Aggregation is a stronger form of dependency-see page 467

has-a relationship § Establishes has-a relationship/association between classes § Bank. Account § One can navigate from one class to another § instantiation in Java – (note NOT inheritance)

Aggregation arrows Arrow with diamond head: one class uses the other by linking methods of the other class. l The arrow indicates the direction of the aggregation

dependency

Multiplicity (Cardinality) • Place multiplicity notations near the ends of an association.


Lab and Home. Work l. Program Exercises P 3. 1 and P 3. 2

Inheritance � Inheritance : allows a developer to derive a new class from an existing one � Parent class, or superclass, or base class. � Thechild class or subclass. � Component hierarchy:

Inheritance-generalization § Establishes an is-a relationship between a more general class (superclass) and a more specialized class (subclass or base class)

Inheritance Deposit child Is-a component of Bank. Form parent Inheritance should create an is-a relationship, meaning the child is a more specific version of the parent