27
Software Engineering Software Engineering COSC 4460 COSC 4460 Spring 2002 Spring 2002 Hello, world! Hello, world!

Software Engineering COSC 4460 Spring 2002 Hello, world!

Embed Size (px)

Citation preview

Page 1: Software Engineering COSC 4460 Spring 2002 Hello, world!

Software EngineeringSoftware Engineering

COSC 4460COSC 4460

Spring 2002Spring 2002

Hello, world!Hello, world!

Page 2: Software Engineering COSC 4460 Spring 2002 Hello, world!

Applet for “Hello,World!”Applet for “Hello,World!”

import java.awt.Graphics;import java.awt.Graphics;class HelloWorld extends java.applet.Appletclass HelloWorld extends java.applet.Applet {{ public void paint (Graphics g)public void paint (Graphics g) {{ g.drawString(“Hello, World!”, 10, 10);g.drawString(“Hello, World!”, 10, 10); }} } }

Page 3: Software Engineering COSC 4460 Spring 2002 Hello, world!

Review of SymbolsReview of Symbols

Applet

HelloWorld

Graphics

paint()

class

class

class

Generalization

Dependency

Page 4: Software Engineering COSC 4460 Spring 2002 Hello, world!

Class Diagram for HelloWorldClass Diagram for HelloWorld

Applet

HelloWorld

Graphicspaint()

HelloWorld is a class.

Applet is a class.

HelloWorld inherits the properties of Applet and is a child of Applet.

Graphics is a class.

HelloWorld uses the paint method from Graphics.

Page 5: Software Engineering COSC 4460 Spring 2002 Hello, world!

ClassClass

• A class is a description of a set of objects that A class is a description of a set of objects that share the same attributes, operations, share the same attributes, operations, relationships, and semantics.relationships, and semantics.

• A class implements one or more interfaces.A class implements one or more interfaces.

• You use classes to capture the vocabulary of You use classes to capture the vocabulary of the system you are developing.the system you are developing.

• Well-structured classes have crisp boundaries Well-structured classes have crisp boundaries and form a part of a balanced distribution of and form a part of a balanced distribution of responsibilities across the system.responsibilities across the system.

Page 6: Software Engineering COSC 4460 Spring 2002 Hello, world!

Identifying Classes in a ProjectIdentifying Classes in a Project• Modeling a system involves identifying the things Modeling a system involves identifying the things

that are important to your particular view.that are important to your particular view.• These things form the vocabulary of the system you These things form the vocabulary of the system you

are modeling.are modeling.• If you are building a house, walls, doors, windows, If you are building a house, walls, doors, windows,

cabinets, and lights are some of the important things.cabinets, and lights are some of the important things.• Each has a set of properties.Each has a set of properties.• For example, walls have height, witdth and color, For example, walls have height, witdth and color,

doors also have height width and color, but also can doors also have height width and color, but also can open in or out. Lights could have a type, size and open in or out. Lights could have a type, size and intensity.intensity.

Page 7: Software Engineering COSC 4460 Spring 2002 Hello, world!

More on Class PropertiesMore on Class Properties

• Different users might care about different Different users might care about different properties, so all users of the system must be properties, so all users of the system must be considered in the decision of what properties considered in the decision of what properties to use.to use.

Page 8: Software Engineering COSC 4460 Spring 2002 Hello, world!

AttributesAttributes

• Class properties in UML are called attributes.Class properties in UML are called attributes.

• A class is shown in UML as a rectangle.A class is shown in UML as a rectangle.

Shapeoriginwidthheight

move()resize()display()

name

attributes

operations

Page 9: Software Engineering COSC 4460 Spring 2002 Hello, world!

OperationsOperations

• Operations can be defined in a class to change Operations can be defined in a class to change the value of properties or to perform some the value of properties or to perform some action, such as writing the property values.action, such as writing the property values.

• In Java, the operations are called methods.In Java, the operations are called methods.

• In C++, the operations are called functions.In C++, the operations are called functions.

Page 10: Software Engineering COSC 4460 Spring 2002 Hello, world!

Names in UMLNames in UML• Every class must have a name.Every class must have a name.• The “simple name” is just a string of characters.The “simple name” is just a string of characters.• The “path name” is the simple name prefixed with The “path name” is the simple name prefixed with

the complete name of the package where the class is the complete name of the package where the class is located.located.

• If a user defined class is not a part of a package, then If a user defined class is not a part of a package, then it must be located in the same file or directory with it must be located in the same file or directory with the class that calls or uses it.the class that calls or uses it.

Rectangle

Wall

simple names

path names

java::awt::Rectangle

house::structures::Wall

Page 11: Software Engineering COSC 4460 Spring 2002 Hello, world!

Names in UMLNames in UML• Notice that class names start with a capital Notice that class names start with a capital

letter.letter.• Attribute and Operation names start with a Attribute and Operation names start with a

lower case letter, with each word following the lower case letter, with each word following the first word having the first letter capitalized.first word having the first letter capitalized.

height: Float

width: Float

isLoadBearing: Boolean = false

Wall

increaseHeight(increase: Float)

increaseWidthByTen()

Definition for class Wall

Page 12: Software Engineering COSC 4460 Spring 2002 Hello, world!

Stereotypes in UMLStereotypes in UML• You can add to the UML language using You can add to the UML language using

stereotypes.stereotypes.

<<constructor>>New()New(p: Policy)<<process>>Process(o:Order)…<<query>>isSuspect(o:Order)isFraudulent(o:Order)<<helper>>validateOrder(o:Order)

FraudAgent

Definition for class Wall

Page 13: Software Engineering COSC 4460 Spring 2002 Hello, world!

ResponsibilitiesResponsibilities

• A responsibility is a contract or obligation of a A responsibility is a contract or obligation of a class.class.

• Responsibilities are written in free-form text.Responsibilities are written in free-form text.

• They can be written in an extra box at the They can be written in an extra box at the bottom of the class symbol, or they can be bottom of the class symbol, or they can be written as a note.written as a note.

Page 14: Software Engineering COSC 4460 Spring 2002 Hello, world!

Responsibilities in a Class

<<constructor>>New()New(p: Policy)<<process>>Process(o:Order)…<<query>>isSuspect(o:Order)isFraudulent(o:Order)<<helper>>validateOrder(o:Order)

FraudAgent

Responsibilities--determine the risk of a customer order--handle customer-specific criteria for fraud

responsibilities

operations

name

attributes

Page 15: Software Engineering COSC 4460 Spring 2002 Hello, world!

Review of SymbolsReview of Symbols

Applet

HelloWorld

Graphics

paint()

class

class

class

Generalization

Dependency

Page 16: Software Engineering COSC 4460 Spring 2002 Hello, world!

Class Diagram for HelloWorldClass Diagram for HelloWorld

Applet

HelloWorld

Graphicspaint()

HelloWorld is a class.

Applet is a class.

HelloWorld inherits the properties of Applet and is a child of Applet.

Graphics is a class.

HelloWorld uses the paint method from Graphics.

Page 17: Software Engineering COSC 4460 Spring 2002 Hello, world!

Figure 3-3 HelloWorld Figure 3-3 HelloWorld Inheritance HierarchyInheritance Hierarchy

ImageObserver

Object

Component

Container

Panel

Applet

HelloWorld

HelloWorld is a child of Applet.

Applet is a child of Panel.

Etc.

ImageObserver is an interface.

Page 18: Software Engineering COSC 4460 Spring 2002 Hello, world!

Root Package in JavaRoot Package in Java

java

applet

awt

lang

HelloWorld

Each class in the class libraries lives in a package. Sometimes a package lives inside another package.

java.applet.Applet shows the hierarchy of packages and classes.

Page 19: Software Engineering COSC 4460 Spring 2002 Hello, world!

NamesNames

• Package namesPackage names– java.appletjava.applet– java.langjava.lang– java.awt.imagejava.awt.image

• Class names (fully qualified)Class names (fully qualified)– java.applet.Appletjava.applet.Applet– java.lang.Objectjava.lang.Object– java.awt.Graphicsjava.awt.Graphics

Page 20: Software Engineering COSC 4460 Spring 2002 Hello, world!

ComponentsComponents

• Physical pieces of the finished system.Physical pieces of the finished system.

• The Java compiler transforms the source code The Java compiler transforms the source code for a class into a component that can be for a class into a component that can be executed.executed.

Page 21: Software Engineering COSC 4460 Spring 2002 Hello, world!

HelloWorld Components

hello.class

hello.java

hello.html

hello.jpg

Page 22: Software Engineering COSC 4460 Spring 2002 Hello, world!

HelloWorld Components

hello.class

hello.java

hello.html

hello.jpg

Page 23: Software Engineering COSC 4460 Spring 2002 Hello, world!
Page 24: Software Engineering COSC 4460 Spring 2002 Hello, world!
Page 25: Software Engineering COSC 4460 Spring 2002 Hello, world!
Page 26: Software Engineering COSC 4460 Spring 2002 Hello, world!
Page 27: Software Engineering COSC 4460 Spring 2002 Hello, world!