software engineering cosc 4460 spring 2002 hello, world!
TRANSCRIPT
Software EngineeringSoftware Engineering
COSC 4460COSC 4460
Spring 2002Spring 2002
Hello, world!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); }} } }
Review of SymbolsReview of Symbols
Applet
HelloWorld
Graphics
paint()
class
class
class
Generalization
Dependency
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.
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.
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.
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.
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
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.
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
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
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
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.
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
Review of SymbolsReview of Symbols
Applet
HelloWorld
Graphics
paint()
class
class
class
Generalization
Dependency
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.
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.
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.
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
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.
HelloWorld Components
hello.class
hello.java
hello.html
hello.jpg
HelloWorld Components
hello.class
hello.java
hello.html
hello.jpg