Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Advanced OO Programming Methods: (Second Year of Study)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Advanced OO Programming Methods

(second year of study)

AMP - Course 1

The Course Structure Java the programming language


GUI
(Graphic User Interfaces)

OOP Design
Design Patterns UML Phases in the life-cycle of SP
GRASP
(General Responsibility Assignments Software Patterns)
AMP - Course 1 2

Some References
1. 2. 3. Eckel, B., Thinking in Java (3rd ed.), New York: Prentice Hall, 2002. Eckel, B., Thinking in Patterns with Java, MindView Inc, 2004. Gamma, E., Helm, R., Johnson, R., Vlissides, J., Design Patterns - Elements of Reusable Object-Oriented Software, Massachusets, Addison-Wesley, 1994. Larman, C.: Applying UML and Design Patterns: An Introduction to OO Analysis and Design, Berlin: Prentice Hall, 2000. Fowler, M., Patterns of Enterprise Application Architecture, Addison-Wesley, 2002. ***, The Java Tutorial, SUN Microsystems, Inc, 2004. http://java.sun.com/docs/books/tutorial/index.html UML Toolkit, H.E. Eriksson, M. Penker, Wiley &Sons

4. 5. 6. 7.

AMP - Course 1

Pure OOL
C++ hybrid object-oriented programming language

Pure approach to object-oriented programming (Alan Kay): ex. - Smalltalk Everything is an object. A program is a bunch of objects telling each other what to do by sending messages. Each object has its own memory made up of other objects. Every object has a type. All objects of a particular type can receive the same messages. (Substitutability)

Java almost pure OOP language


AMP - Course 1 4

JAVA Language
Why Java? Because it is
simple, object-oriented, distributed and dynamic, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded
AMP - Course 1 5

Java is an interpreted language


The Java compiler generates byte-codes for the Java Virtual Machine (JVM - the interpreter and run-time system), rather than native machine code. Run a Java program= Java interpreter execute the compiled bytecodes Java byte-codes are platform-independent Java programs can run on any platform that the JVM has been ported to. In an interpreted environment, the standard "link" phase of program development pretty much vanishes. If Java has a link phase at all, it is only the process of loading new classes into the environment, which is an incremental, lightweight process that occurs at run-time.

AMP - Course 1

How a Java program is executed?


bytecode MyClass.java compilation MyClass.class executed by Java Virtual Machine executed on Host Machine

> javac MyClass.java > java MyClass


AMP - Course 1 7

A Simple Example Hello World!


public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } > javac HelloWorld.java > java HelloWorld
AMP - Course 1 8

Analysis and Design


1. Object discovery 2. Object assembly 3. System construction 4. System extension 5. Object reuse

AMP - Course 1

N-tier application architecture


A model for developers to create a
flexible and reusable

application. By breaking up an application into tiers, developers only have


to modify or add a specific layer, rather than have to rewrite the entire application over.

There should be at least 3 t.:


a presentation tier, a business or domain tier, and a storage tier.

AMP - Course 1

10

Layers as an architectural pattern


In object-oriented design, a layer = a group of classes that have the same set of link-time module dependencies to other modules. In other words, a layer is a group of reusable components that are reusable in similar circumstances.

AMP - Course 1

11

layer and tier


The concepts of layer and tier are often used interchangeably. However, one fairly common point of view is that there is indeed a difference, and that a layer is a logical structuring mechanism for the elements that make up the software solution, while a tier is a physical structuring mechanism for the system infrastructure.

AMP - Course 1

12

The three-tier architecture


Presentation tier
This is the topmost level of the application. The presentation tier displays information related to services as:
browsing merchandise, purchasing, and shopping cart contents.

It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.

Application tier (business logic, logic tier, domain tier, data access tier, or middle tier)
The logic tier is pulled out from the presentation tier and, as its own layer, it controls an applications functionality by performing detailed processing.

Data tier
This tier consists of database servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data its own tier also improves scalability and performance.

AMP - Course 1

13

Historical perspective
The three-tier architecture concept emerged in the 1990s from observations of distributed systems (e.g., web applications) where the client, middleware and data tiers ran on physically separate platforms.

AMP - Course 1

14

Object Oriented Analysis and Design


Purpose: the creation of well designed, robust, and
maintainable software systems using OO technology and OOLs

Object vs. Function Oriented Analysis and Design


Decomposition (divide&conquer) is the primary strategy to deal with the complexity of software systems. Structured analysis and design:
decomposition by functions or by processes decomposition by objects or concepts
AMP - Course 1 15

OO analysis and design:

OOA and OOD


Use UML Iterative developments cycles
Phases of a cycle:

1. Plan and elaborate phase 2. Analyze phase 3. Design phase 4. Construct (implementation) phase

| | Build Phase |

Cycles

AMP - Course 1

16

Use Cases and Development Cycles


A use case is a narrative description of a domain process. Iterative development cycles are organized by use cases requirements. Ranking use cases take first the use cases that significantly influence the core architecture by fleshing out the domain and high-level services layers or the critical use cases.

AMP - Course 1

17

The Plan and Elaborate Phase


includes the initial conception, investigation of alternatives, planning, specification of requirements

Artifacts:
Plan: schedule, resources, budget, Preliminary Investigation Report: motivation, alternatives,.. Requirements Specification: declarative statement of requirements Glossary: a dictionary of terms and any associated information Prototype: a prototype system created to aid understanding of the problem, high risk problems, and requirements. Use Cases: prose description of domain processes Use Cases Diagrams: illustration of all use cases and their relationships Draft Conceptual Model: a rough preliminary conceptual model as an aid in understanding the vocabulary of the domain
AMP - Course 1 18

Case study: Point-of-Sale


Architectural Layers
Presentation (minor focus) Application Logic problem domain objects (Sale, Payment,) (primary focus) service objects (DatabaseBroker,SecurityManager) (secondary focus) Storage

AMP - Course 1

19

Requirements - Basic Functions


Ref# R1.1 R1.2 R1.3 R1.4 R1.5 R1.6 R1.7 R1.8 R1.9 Function Record the current sale the items purchased. Calculate current sale total, including tax and coupon calculations Capture purchase item information from a bar code. Reduce inventory quantities when a sale is committed. Log completed sales Cashier must log in with an ID and password Provide a persistent storage mechanism Provide inter-process and inter-system communication mechanism. Display description and price of item recorded
AMP - Course 1

Category evident evident evident hidden hidden evident hidden hidden evident
20

Requirements - Payment Functions


Ref# R2.1 R2.2 Function Handle cash payments, capturing amount tendered and calculating balance due. Category evident

Handle credit payments, capturing credit information evident from a card reader ar by manual entry, and authorizing payment with the stores credit authorization service via a modem connection. Handle check payments, and authorizing payment with the stores credit authorization service via a modem connection. Log credit payments to the accounts receivable system, since the credit authorization service owns the store the payment amount.
AMP - Course 1

R2.3

evident

R2.4

hidden

21

Use Cases
A use case = a narrative document that describes the sequence of events of an actor (an external agent) using a system to complete the process They illustrate and imply requirements. The UML Icon:
Buy Items

A use case is a relatively large end-to-end process description that typically includes many steps or transactions;
is it not normally an individual step or activity in a process.
AMP - Course 1 22

The Use Case: Buy Items


Use Case: Buy Items with cash Actors: Cashier, Customer (initiator) Type: primary Description: A Customer arrives at a checkout with items to purchase. The Cashier records the purchase items and collects payment. On completion, the Customers leaves with the items Cross References: Functions: R1.1, R1.2,R1.3, R1.7, R1.9, R2.1 Exceptions: A bar code is not valid -> cancel for that product. The payment is not valid -> cancel the whole sale.

AMP - Course 1

23

Typical Course of Events


(for Buy Items)
Actor Actions 1. Customer arrives at the POST checkout with items to purchase. 2. The Cashier records each item. If there are more than one of the same item, the Cashier can enter the quantity as well. 4. On completion of item entry, the Cashier indicates to the POST that the Sale is complete. 6. The Cashier informs the Customer about the total. 7. Customer chooses payment type:
a) b) c) If Cash payment, initiate Pay by Cash If credit payment, initiate Pay by Credit If check payment, initiate Pay by Check

System Response 3. Determines the item price and adds the item information to the running sale transaction. 5. Calculates and display the sale total.

AMP - Course 1

24

Use Case Diagrams


Log in

Cashier

Buy Items

Customer

Refund Purchased Items

SystemAdministrat or

Manage Users

Start Up

Manager

AMP - Course 1

25

Identify Actors and Use Cases

Cashier Customer Manager System Administrator

Log In Cash Out Buy Items Refund Items Start Up Shut Down Add New Users
AMP - Course 1 26

Ranking & scheduling use cases


Rank use-cases Where is necessary create simplified versions of use cases. Allocate use-cases to development cycles.

Example Use cases: - Buy item - Add new users - Log in - Refund items - Start up - Shut down Priority High | | Medium | | Low |

AMP - Course 1

27

UML (Unified Modeling Language)


UML is the industry-standard language for specifying, visualizing, constructing, and documenting the artifacts of software systems UML is the standard notation for software architecture Online UML Resources
Rational Software -- UML Resource Center (http://www-306.ibm.com/software/rational/uml/), The Object Management Group http://www.uml.org/

AMP - Course 1

28

UML(2)

Data types: Integer, Real, String, Character


AMP - Course 1 29

UML(3)

AMP - Course 1

30

UML(4)

AMP - Course 1

31

UML(5)

AMP - Course 1

32

UML Examples - Association


Simple Association
Uses

Author

Computer

Person

1..*

Owns Owned by

0..*

Car

Navigable Association

Person

Owns

0..*

Car

AMP - Course 1

33

UML Examples - Association


Qualified Association
Owns

Canvas

FigureId

0..*

Figure

Or-Association

0..* Insurance
Contract Insurance Company

0..* (or) 1..*


Company
34

0..* 1..*
Person
AMP - Course 1

UML Examples - Association


Association Class Marriage

Men

Woman

The association class is used to add extra information on a link.

AMP - Course 1

35

UML Examples - Aggregation


Simple Aggregation

Team

Contains
1..*

Player

Composition Aggregation

Window

TitleBar

*
AMP - Course 1

Menu
36

UML Examples Generalization/Specialization

Person

Student

AMP - Course 1

37

UML Examples -Dependency

Class A Class A depends on class B.

Class B

A change in the independent class affect the dependent class

AMP - Course 1

38

UML(6)

Use-case diagrams Collaboration diagrams Sequence diagrams

AMP - Course 1

39

Java features

AMP - Course 1

40

Architecture Neutral and Portable


A Java application can run on any system, as long as that system implements the Java Virtual Machine. This is important for applications distributed over the Internet or other heterogeneous networks. Byte-code format is one big part of being portable. There are no "implementation-dependent" aspects of the language specification.

(For example, Java explicitly specifies the size of each of the primitive data types, as well as its arithmetic behavior. In C an int type can be 16, 32, or 64 bits long depending on the platform.)

"Write Once, Run Anywhere."

AMP - Course 1

41

Dynamic and Distributed


Java is a dynamic language.
Any Java class can be loaded into a running Java interpreter at any time. These dynamically loaded classes can then be dynamically instantiated. Native code libraries can also be dynamically loaded. Classes in Java are represented by the Class class; you can dynamically obtain information about a class at run-time.

Java is a distributed language =


it provides a lot of high-level support for networking. URL class and related classes in the java.net package Remote Method Invocation (RMI) traditional lower-level networking support (datagrams and stream-based connections through sockets)

These features make it possible for a Java interpreter to download and run code from across the Internet (ex. Java applets)
AMP - Course 1 42

Simple
Java is a simple language
could be learned quickly the number of language constructs has been kept relatively small there are a lot of similarities with C++ A number of features available in C and C++ have been removed: No goto statement; instead there are labelled break and continue statements and exception handling. Java does not use header files and it eliminates the C preprocessor. No struct and union No operator overloading and multiple inheritance

Java does not use pointers


Java automatically handles the referencing and dereferencing of objects Automatic garbage collection

Java is actually a full-featured and very elegant language


AMP - Course 1 43

Robust
Java is a strongly typed language extensive compile-time checking for type-mismatch problems.
Java is more strongly typed than C++. Java requires explicit method declarations; it does not support C-style implicit declarations the compiler can catch method invocation errors.

No pointers increases the robustness of Java programs by abolishing an entire class of pointer-related bugs. All accesses to arrays and strings are checked at run-time to ensure that they are in bounds, eliminating the possibility of overwriting memory and corrupting data. Casts of objects from one type to another are also checked at run-time to ensure that they are legal. Java's automatic garbage collection prevents memory leaks and other pernicious bugs related to memory allocation and de-allocation. Exception handling is another feature in Java that makes for more robust programs.
AMP - Course 1 44

Secure
Security is very important because of the distributed nature of Java. Java was designed with security in mind, and provides several layers of security controls: 1. At the lowest level, security goes hand-in-hand with robustness. 2. The Java interpreter performs on any untrusted code it loads a byte-code verification process . (These verification steps ensure that the code is well-formed--that it doesn't overflow or underflow the stack or contain illegal byte-codes, for example.) 3. The "sandbox model": untrusted code is placed in a "sandbox," where it can play safely, without doing any damage to the "real world," or full Java environment. (It is executed with some restrictions.) 4. By attaching a digital signature to Java code, the origin of that code can be established in a cryptographically secure and unforgeable way.
AMP - Course 1 45

High-Performance and Multithreaded


Java is an interpreted language, so it is never going to be as fast as a compiled language like C. Compiled C code runs ten times as fast as interpreted Java byte-codes.
This speed is more than adequate to run interactive, GUI and network-based applications, where the application is often idle, waiting for the user to do something, or waiting for data from the network. The speed-critical sections of the Java run-time environment, that do things like string concatenation and comparison, are implemented with efficient native code.

Many Java interpreters now include "just in time" compilers that can translate Java byte-codes into machine code for a particular CPU at runtime. Java is a multithreaded language;
it provides support for multiple threads of execution that can handle different tasks.

AMP - Course 1

46

Internationalization
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes.

An internationalized program has the following characteristics: With the addition of localized data, the same executable can run worldwide. Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically. Support for new languages does not require recompilation. Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language. It can be localized quickly.
AMP - Course 1 47

Unicode
Java characters, strings, and identifiers (e.g., variable, method, and class names) are composed of 16-bit Unicode characters. This makes Java programs relatively easy to internationalize for nonEnglish-speaking users. Since most operating environments do not support Unicode, Java uses a pre-processing phase to make sure that all of the characters of a program are in Unicode. Java defines escape sequences that allow all characters that can be represented in Unicode to be represented in other character encodings, such as ASCII or EBCDIC. Unicode defines the codes 0 through 127 to be consistent with ASCII.

(\uxxxx, where xxxx is a sequence of four hexadecimal digits )

char newline = '\n', apostrophe = '\", delete = '\377; char aleph='\u05D0, a = A, aa=\u0103;

AMP - Course 1

48

You might also like