introduction (1) chapter 1 (1) object-oriented modeling and design byung-hyun ha [email protected]

43
Introduction (1) Chapter 1 (1) Object-Oriented Modeling and Desig n Byung-Hyun Ha [email protected]

Upload: maud-newman

Post on 01-Jan-2016

225 views

Category:

Documents


1 download

TRANSCRIPT

Introduction (1)

Chapter 1 (1)

Object-Oriented Modeling and Design

Byung-Hyun Ha

[email protected]

Lecture Outline

Prolog

Preface (in the Textbook)

Introduction

Object-oriented

Basics in Java programming

Caution!

My English

I’d like to hear from you, if you cannot understand my words, please.

Prolog

This course is about software engineering or software development, not about computer programming including object-oriented languages and coding.

However, if you are not familiar with computer programming, it will never easy to understand concepts in this book.

That is, the audience of this course is those who have experience of computer programming.

Prolog

Who need to take this course Those who want to be a professional programmer, Those who want to be a S/W library developer, Those who want to be (software) system engineer, Those who want to learn a new way of thinking for world

(system) Those who wonder what SE is, or …

Who can take this course those who have experience of participating in large S/W

development process, those who have basic knowledge in programming, those who want to learn SE, those who have to take qualified exam, or …

Prolog

Who may make mistake of taking this course those who believe this course will improve their knowledge about

computer or computer programming, those who expect this course will improve their computer progra

mming skill, those who want to learn how to implement Heuristic algorithms fo

r the problems in the projects they participate in, those who believe it is quite sufficient for computer applications

(programs) to run without error, those who hate complex approach to simple problems, and …

Prolog

Say again,

Computer programming skill for industrial engineer Very important! because if they have the skill, they can do much

deeper study during their research. But this course is for (software) system engineering!

I recommend a course from Prof. Ryu, our new professor.

Course Material

Textbook Rumbaugh et al., Object-Oriented Modeling and Design, Prentice

-Hall, Inc., NJ, 1991• the predecessor of UML (Unified Modeling Language)

References Whitten, Bentley, Dittman, Systems Analysis and Design Method

s, 6th Ed., McGraw-Hill, 2004 Gamma et al., Design Patterns: Elements of Reusable Object-Ori

ented Software, Addison-Wesley, 1995

Course Plan

Introduction Including Java language review

Modeling concepts Object modeling Dynamic modeling Functional modeling

Design methodology Analysis System design Object design

Implementation & applications

Student Evaluation

Attendance: 10%

Homework: 20% may include java programming

Mid/final exam: 35%

Term project: 35%

Preface (in the Textbook)

An object-oriented approach to software development based on modeling objects from the real world and then using the model to build a language-independent

design organized around those objects

Object-oriented modeling and design promote better understanding of requirements cleaner design more maintainable (information) systems

In this course a set of object-oriented concepts a language-independent graphical notation

• Object Modeling Technique

Preface (in the Textbook)

Object Modeling Technique analyze problem requirements design a solution to the problem implement the solution in a programming language or database

the same concepts and a notation to be used throughout the entire software development process, does not need to translate into a new notation at each development stage

Object-oriented technology is more than just a way of programming a way of thinking abstractly about a problem using real world

concepts, rather than computer concepts

Think in terms of application, not of computer!

Introduction

Object-oriented modeling and design a new way of thinking about problems using models organized

around real-world concepts

Fundamental concept is object, which combines both data structure and behavior in a single

entry

OOMD lifecycle First, analysis model to abstract essential aspects of application

domain• without regard for eventual implementation

Then, design decisions are made and details are added Finally, design model is implemented

Object-Oriented

“Object-oriented” means we organize software as a collection of discrete objects that

incorporate both data and behavior

Required characteristics Identity Classification Polymorphism Inheritance

Object-Oriented

Identity Data is quantized into discrete, distinguishable entities called

objects• e.g. a paragraph in a document, a window on my PC, white queen in

a chess game

Objects can be concrete or conceptual• e.g. a file in a file system, a scheduling policy

Each object has its own inherent identity• Two objects are distinct even if their attribute values (such as name

and size) are identical

Object-Oriented

Classification Objects with the same data structure (attributes, signature, …)

and behavior (operations, methods, …) are grouped into a class A class is an abstraction that describes properties important to

an application and ignores the rest Each class describes a possibly infinite set of individual objects

• Each object is said to be an instance of its class

Polymorphism The same operation may behave differently on different classes

Inheritance The sharing of attributes and operations among classes based

on a hierarchical relationship

Object-Oriented

Anyway, what is object-oriented? Before moving further, let’s review the object-oriented using Java

Java Programming

I recommend Eclipse for Java programming

Hello World!

First, you have to memorize!

public class Hello {

public static void main(String[] args) {System.out.println("Hello World!");System.out.println("Hello Java!");

}}

Hello World!Hello Java!

Java Programming Using Eclipse

Select [File – New – Java Project], enter project name, select [Finish] button

Java Programming Using Eclipse

Select [File – New – Class], enter class name (Hello), select [Finish] button

Java Programming Using Eclipse

Type codes and save it

Java Programming Using Eclipse

Execute by selecting run button ( )

Arithmetic Operations

Numerical and string-wide

public class Calc {

public static void main(String[] args) {System.out.println(127.0 * 135.0 - 562.5 / 23.2);

}}

public class StringAdd {

public static void main(String[] args) {System.out.println("I" + " am " + "handsome");

}}

Arithmetic Operations

Mixed form

public class StringAdd {

public static void main(String[] args) {System.out.println("I" + 13 + 4 + "handsome");

}}

I134handsome

Variables

Primitive types

public class Variable {

public static void main(String[] args) {int a;int b;

a = 2;b = 3;a = b;System.out.println(a);

a = a + 5;System.out.println(a);

}}

Numerical Type

Integral types byte: 8-bit, 128 to 127 short: 16-bit, 32768 to 32767 int: 32-bit, 2147483648 to 2147483647 long: 64-bit, 9223372036854775808 to 9223372036854775807 char: 16-bit, 0 to 65535

Floating-point types float: 32-bit double: 64-bit

Swapping Values

Wrong implementation

public class Swap {

public static void main(String[] args) {int a = 1;int b = 2;

b = a;a = b;

System.out.println(a + " " + b);}

}

Swapping Values

Correct one

public class Swap {

public static void main(String[] args) {int a = 1;int b = 2;

int c = a;a = b;b = c;

System.out.println(a + " " + b);}

}

Arrays

A collection of values

public class Array {

public static void main(String[] args) {int[] a = new int[3];a[0] = 10;a[1] = 5;a[2] = 7;

System.out.println(a[0] + " " + a[1] + " " + a[2]);}

}

Arrays

Using variable as reference

public class Array {

public static void main(String[] args) {int[] a = new int[3];a[0] = 10;a[1] = 5;

int[] b = a;b[2] = 7;

System.out.println(a[0] + " " + b[1] + " " + a[2]);}

}

Arrays

Indexing using variables

public class Index {

public static void main(String[] args) {double[] a = new double[3];int b = 2;

a[b] = 5.5;a[b - 1] = -3.2;a[0] = 4.1;

System.out.println(a[b - 2] - a[1]);}

}

Arrays

Multi-dimensional array

public class TwoDim {

public static void main(String[] args) {int[][] a = new int[2][3];a[0][0] = 1;a[0][1] = 2;a[0][2] = 3;a[1][0] = 4;a[1][1] = 5;a[1][2] = 6;

System.out.println(a[1][2]);System.out.println(a[0][1]);

}}

Handling Text String in Java

Actually implemented by String class

public class StringClass {

public static void main(String[] args) {String a = new String("This is string");String b = "For simplicity";

String c = b + " " + a;System.out.println(c);

}}

Operations

Check leap year

public class Lunar {

public static void main(String[] args) {int year = 2000;boolean p = ((year % 4) == 0);boolean q = ((year % 100) != 0);boolean r = ((year % 400) == 0);System.out.println((p && q) || r);

year = 2004;p = ((year % 4) == 0);q = ((year % 100) != 0);r = ((year % 400) == 0);System.out.println((p && q) || r);

}}

User Input Processing

Check leap year by user input

public class IsLunar {

public static void main(String[] args) {java.util.Scanner s = new java.util.Scanner(System.in);

System.out.print("Input year: ");int year = s.nextInt();

boolean p = ((year % 4) == 0);boolean q = ((year % 100) != 0);boolean r = ((year % 400) == 0);System.out.println((p && q) || r);

}}

Java API Reference (Have to Be Installed)

HW1: Sum from n to m

Run sample

For every HW, send e-mail to me by one day before the next lecture

Input n: 8Input m which is more than 8: 10Sum from 8 to 10 is 27.

Control Flow

If statement

public class EvenOdd {

public static void main(String[] args) {java.util.Scanner s = new java.util.Scanner(System.in);System.out.print("Input an integer: ");int a = s.nextInt();

if ((a % 2) == 0) {System.out.println(a + " is an even number.");

} else {System.out.println(a + " is an odd number.");

}}

}

Control Flow

Nested if statements

public class Score {

public static void main(String[] args) {java.util.Scanner s = new java.util.Scanner(System.in);System.out.print("Your points? ");int points = s.nextInt();

if (points > 80) {if (points == 100) {

System.out.println("A");} else {

System.out.println("B");}

} else {System.out.println("F");

}}

}

Control Flow

for statement

public class Gugu {

public static void main(String[] args) {java.util.Scanner s = new java.util.Scanner(System.in);System.out.print("For what? ");int n = s.nextInt();

for (int i = 1; i <= 9; i++) {System.out.println(n + " * " + i + " = " + n * i);

}}

}

Control Flow

while statementpublic class Binary {

public static void main(String[] args) {java.util.Scanner s = new java.util.Scanner(System.in);System.out.print("Input decimal number: ");int n = s.nextInt();

int[] digits = new int[32];int i = 0;while (n > 0) {

digits[i] = n % 2;n = n / 2;i++;

}for (int j = i - 1; j >= 0; j--) {

System.out.print(digits[j]);}

}}

HW2: Displaying Diamonds

Write code of displaying diamonds as follows

Height? 3Number? 4 * * * * *** *** *** *** ***** ***** ***** ***** *** *** *** *** * * * *

Height? 5Number? 2 * * *** *** ***** ***** ******* ******* ********* ********* ******* ******* ***** ***** *** *** * *