Designing a Java Program Principles of Software Engineering

  • Slides: 56
Download presentation
Designing a Java Program Principles of Software Engineering INFSY 535

Designing a Java Program Principles of Software Engineering INFSY 535

Extreme Programming l l l Program design and resulting code are outcomes of a

Extreme Programming l l l Program design and resulting code are outcomes of a partnership. Concept of collaboration Based on: • • • communication, simplicity, feedback

XP: Extreme Programming • keep design simple and clean. • feedback is immediate by

XP: Extreme Programming • keep design simple and clean. • feedback is immediate by testing software • • starting on day one. Software is delivered quickly to the customers Changes are implemented as a direct result of customer feedback.

l “Driver: and “Navigator’ • Driver: types at the computer or writes down design

l “Driver: and “Navigator’ • Driver: types at the computer or writes down design methods l “Navigator” • person who observes the driver’s work and is attentive for tactical and strategic defects. l Roles are reversed on a periodic basis

l l Pair programming encompasses more than writing code and includes the design, testing,

l l Pair programming encompasses more than writing code and includes the design, testing, and so forth. Research has found: • • • pairs developed better code with a very minimal increase in prerelease programmer hours, pairs enjoyed their work more than programmers who worked individually, and pairs overcame many technical problems by pooling joint knowledge.

Systems l l l Small systems • • Current assignments Built without much planning

Systems l l l Small systems • • Current assignments Built without much planning Limited ability to comprehend large systems Simulation of larger systems • • A modeling activity Object Oriented approach breaks a complex system into small parts

Service-Oriented Architecture (SOA) Computer World, August 15, 2005 a) Emphasis on reuse of code

Service-Oriented Architecture (SOA) Computer World, August 15, 2005 a) Emphasis on reuse of code b) Reuse of application components tied together as services c) the requirements phase of development projects assessment of opportunities to reuse project components.

Service-Oriented Architecture (SOA) 1. Accenture Ltd. today announced a new $450 million service-oriented architecture

Service-Oriented Architecture (SOA) 1. Accenture Ltd. today announced a new $450 million service-oriented architecture initiative that includes developing a new research laboratory and building SOA applications customized for specific industries. The Accenture Technology Lab for SOA Innovation will initially focus on the health care industry with an e-prescription project that will tackle integrating the multiple steps to filling a prescription. (7, 2006)

Service-Oriented Architecture (SOA) 1. IBM has bought services-oriented architecture ( SOA ) vendor Webify

Service-Oriented Architecture (SOA) 1. IBM has bought services-oriented architecture ( SOA ) vendor Webify Solutions Inc. and plans to make it a part of IBM's Software Group and Web. Sphere middleware product family. (8/2006)

Software Projects The larger the project, the higher proportion of costs is time spent

Software Projects The larger the project, the higher proportion of costs is time spent communicating

Program Design 1. Understand the program 2. requirement Analysis I/O is critical 3. Write

Program Design 1. Understand the program 2. requirement Analysis I/O is critical 3. Write and test each part (unit testing implementation 2. Specify what the solution Must do! Model/design (UML comes into play) 4. Maintenance

UML Class Diagrams How to model/design/represent the solution? (Iguana example)

UML Class Diagrams How to model/design/represent the solution? (Iguana example)

Iquana Example UML attribute Iguana cage 1…* 1 1…* bowl associations - _color: Color

Iquana Example UML attribute Iguana cage 1…* 1 1…* bowl associations - _color: Color 4 -_left. Back. Leg, _right. Back. Leg: Leg - _food. Dish: Bowl Leg is a component - _cage: Cage + Iguana + move(): void + eat (): void object Iguana is the container object May create multiple instances

UML Class Diagrams Preparation: • • • Verbally describe the situation – text page

UML Class Diagrams Preparation: • • • Verbally describe the situation – text page 19 Find the objects (nouns) that will be part of model Describe properties of the objects • • Establish relations between the objects Place the objects in groups • Attributes or characteristics • Parts or components • Associations

Java facilitates working with Objects Terminology: l Objects are abstractions l Objects are manipulated

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 Java facilitates working with Objects l Constructor: a kind of method (called automatically

l Java facilitates working with Objects l Constructor: a kind of method (called automatically when a class is instantiated)

Java Class Concept Encapsulation • Blackbox concept methods called Interface Data and method(s) Hidden

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

Components of the UML l Class Diagram l Object Diagram Use Case Diagram State

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

UML Class Models l Documents the static structure of a system • Shows classes/objects

UML Class Models l Documents the static structure of a system • Shows classes/objects • Relationships to each other

Relationships Between Objects l Types of relationships: • has-a • Is-a

Relationships Between Objects l Types of relationships: • has-a • Is-a

has-a relationship § Establishes has-a relationship/association between classes § Bowl, Cage and iguana are

has-a relationship § Establishes has-a relationship/association between classes § Bowl, Cage and iguana are classes § iguana has-a bowl and has-a cage § You can navigate from one class to another § instantiation in Java – (note not inheritance)

Association arrows Arrow with (or without) arrowhead: one class uses the other by linking

Association arrows Arrow with (or without) arrowhead: one class uses the other by linking methods of the other class. l Draw a single line between objects or classes l An arrow can indicate the direction of the association

has-a arrows iquana has-a cage

has-a arrows iquana has-a cage

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

Multiplicity (Cardinality) • • • Place multiplicity notations near the ends of an association. These symbols indicate the number of instances of one class linked to one instance of the other class. For example, one company will have one or more employees, but each employee works for one company only.

Of Note: l Annotations (optional on diagram) • x…y: x or greater and less

Of Note: l Annotations (optional on diagram) • x…y: x or greater and less than or equal to y • Finite number is the number itself • * after the number: no upper bound

Inheritance l Inheritance allows a developer to derive a new class from an existing

Inheritance l Inheritance allows a developer to derive a new class from an existing one l The existing class is called the parent class, or superclass, or base class. l The derived class is called the child class or subclass. l Component hierarchy: Collection of parts and subparts l Container object: one that contains the component object Iguana is the container object Leg is a component object

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

Inheritance-generalization § Establishes an is-a relationship between a more general class (superclass) and a more specialized class (subclass or base class) § One class is a component of another § iquana is a superclass and extends leg, the base class

Inheritance l Shown in a UML class diagram, with an arrow with an open

Inheritance l Shown in a UML class diagram, with an arrow with an open arrowhead pointing to the parent class leg child Is-a component of iguana parent Inheritance should create an is-a relationship, meaning the child is a more specific version of the parent

Iquana Example UML attribute Iguana cage 1…* 1 1…* bowl associations - _color: Color

Iquana Example UML attribute Iguana cage 1…* 1 1…* bowl associations - _color: Color 4 -_left. Back. Leg, _right. Back. Leg: Leg - _food. Dish: Bowl Leg is a component - _cage: Cage + Iguana + move(): void + eat (): void object Iguana is the container object May create multiple instances

§ Models a customer order from a retail catalog. • Central class is the

§ Models a customer order from a retail catalog. • Central class is the Order. • Associated with it are the Customer making the purchase and the Payment. • A Payment is one of three kinds: Cash, Check, or Credit. • The order contains Order. Details (line items), each with its associated Item.

Instructions for September 19 th Class l l Read assigned text material Complete ANGEL

Instructions for September 19 th Class l l Read assigned text material Complete ANGEL quiz prior to class time (6: 15 PM) on September 19 Complete the Eclipse Tutorial linked on the main section of the syllabus and on the syllabus Using Power. Point slides – posted in ANGEL, complete lab 3.

Project I l l Complete all work from previous slide prior to beginning project

Project I l l Complete all work from previous slide prior to beginning project 1. See Project 1 on Syllabus next week. See Project Instructions linked to both the syllabus and the project instructions. Due September 26: • • • Study composite objects in text book UML Diagram for project 1 Main class and shells for another class.

UML: Universal Modeling Language l l l Rectangles Three sections: • Class/object name •

UML: Universal Modeling Language l l l 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

Class Diagram with Variables and Methods Class Name Visibility: private - Attributes/ characteristics: variables public + (chapter 3) Methods/capabilities Iguana - _color: Color -_left. Back. Leg, _right. Back. Leg: Leg - _food. Dish: Bowl - _cage: Cage + Iguana + move(): void + eat (): void

Using VISIO 2003 to Produce UML Diagrams l Click on VISIO • Visio can

Using VISIO 2003 to Produce UML Diagrams l Click on VISIO • Visio can be found in the Start/programs menu or on the desktop l Select the Software Category • If not already selected • Left hand menu on screen

Lab 2 l l l Using the slides that follow • Create the Iquana

Lab 2 l l l Using the slides that follow • Create the Iquana Model using VISIO • Place in drop box titled Iquana UML Diagram Be sure to use the text tool on the toolbar to add your name to the drawing Place in dropbox, Iquana UML Diagram Drop Box

Opening Screen l l The left-hand column is labeled Category. This column contains folders

Opening Screen l l The left-hand column is labeled Category. This column contains folders of drawing templates for different types of diagrams

l Scroll Down (under template section) to tool labeled UML Model Diagram-US Units l

l Scroll Down (under template section) to tool labeled UML Model Diagram-US Units l The scroll bar Is on the right side of the screen! l Click on the UML icon

Description of Work Area (Normal menu and icon bars are at the top of

Description of Work Area (Normal menu and icon bars are at the top of the window. ) Shapes Window Graph paper on which to draw Model Explorer Window

Work Area Usual Menus and icons Expand Shapes by: l l Select this line

Work Area Usual Menus and icons Expand Shapes by: l l Select this line Click on small square beside ‘Shapes”

Work Area Model Explorer If the tree view isn't visible, click on: §UML §View

Work Area Model Explorer If the tree view isn't visible, click on: §UML §View §Model Explorer

Shapes Window q Class Diagrams depict the structure of a project. • Note that

Shapes Window q Class Diagrams depict the structure of a project. • Note that from the group labeled UML Static Structure • You will drag class or object shapes onto the drawing page. • In this manner, you will represent classes or objects.

Create a class diagram (model) q q Drag the class icon into the work

Create a class diagram (model) q q Drag the class icon into the work area. To format text (you will need to make text larger). § Format § Text § 18 or 24 pt suggested § Click on “apply” § Click on “ok” q In Model Explorer Class Name of your choice § Right Click on “class 1” § Rename your class to be Iguana

Attributes and operations q q Iguana - _color: Color -_left. Back. Leg, _right. Back.

Attributes and operations q q Iguana - _color: Color -_left. Back. Leg, _right. Back. Leg: Leg - _food. Dish: Bowl - _cage: Cage + Iguana + move(): void + eat (): void So far – a class is modeled on the diagram and you have determined the class name Next consider: § the state (attributes) and § behavior (operations) of the objects of these classes!

Properties • Attributes: are program variables • Operations: are program methods

Properties • Attributes: are program variables • Operations: are program methods

Add a data/variable type l Adapting the C# data types option for our use.

Add a data/variable type l Adapting the C# data types option for our use. (There is no Java data type in Visio). • Right click on C# Data Type (under model explorer), to add any datatype desired! • New • Datatype • Insert String in the name field

Add class attributes q Using the Class on the Class Diagram diagram § Right

Add class attributes q Using the Class on the Class Diagram diagram § Right Click on the diagram or class name in Model Explorer <class Name> § Select Properties § Select Attributes § Click on New button

q q q A spreadsheet row appears Click in the attribute fields • Fill

q q q A spreadsheet row appears Click in the attribute fields • Fill in an attribute name field (e. g. _left. Back. Leg Tab to the next column • Fill in the data type as double, integer, Leg. If the type is available, add it as you did the String type • Leave the visibility as private (- will appear in diagram) Click on the OK Button Repeat for all attributes

Visibility: A marker that signifies who can access the information contained within a class.

Visibility: A marker that signifies who can access the information contained within a class. • private visibility hides information from anything outside the class partition. (-) • public visibility allows all other classes to view the marked information. (+) • protected visibility allows child classes to access information they inherited from a parent class. (*)

Visibility Modifiers

Visibility Modifiers

Simple Attribute Representation Attributes are specified according to the following: Visibility name: type=default-value •

Simple Attribute Representation Attributes are specified according to the following: Visibility name: type=default-value • public (+), protected (#), private (-) • The visibility name is a string by which • • attribute is identified The visibility type is attribute type Default-value is assigned unless specified

Adding other method objects q q q Right-click on the Iguana class icon Select

Adding other method objects q q q Right-click on the Iguana class icon Select properties Select Operations • Click in the Operation box • Enter other public operation names e. g. + move(): void + eat (): void

Adding other method objects • void is the return type for all the methods

Adding other method objects • void is the return type for all the methods • Leave public as the visibility for these methods

The Constructor method q q q Right-click in your model drawing on the class

The Constructor method q q q Right-click in your model drawing on the class icon Select properties Select Operations • Click in the Operation box • Enter Iquana as the operation name • Leave none as the return type • Leave public as the visibility • Click on OK