- Coding is an end goal of software development.
- Iterative and incremental development process results in the feeding of prior iteration into the beginning of next iteration, continuously refining the implementation works.
- It involves the implementations of object oriented design into the object oriented programming code.
- It requires writing code for:
a) Class and interface definitions
b) Method definitions
- Class definitions are created by mapping design class diagrams to code.
- Method definitions are created by mapping interaction diagrams to code.
Example 1
Example 2
- The sequence diagram consists of sequence of messages which are translated to a series of statements in the method definitions.
Example 1
Collection Classes in Code
- One to many relationships are common.
- Such relationships is implemented using collection object such as list, map or array.
- The choice of collection class is influenced by the requirements. i.e. key based lookup requires Map while growing ordered list requires a List.
- If object implements an interface, declare the variable in terms of the interface.
Example 1
Example 2
Exception
- An exception is a condition that is caused by a runtime error in the program.
- An exception may occur due to following reasons:
a) Invalid data entered by a user.
b) File to be opened can not be found.
c) The network connection has lost in the middle of the communication
Sources for Exceptions
1. User errors
2. Programmer errors
3. Physical resource failure
Categories of Exception
1. Checked Exception:
- It is the exception that can not be foreseen by the programmer.
- Eg: FileNotFoundException
2. Runtime Exception:
- It is the exception that could be avoided by the programmer.
- It is ignored at the time of compilation.
3. Errors:
- They are the problems beyond the control of user and programmer.
- Eg: StackOverflowException
Exception Handling Process
- In object oriented programming languages, there is a mechanism to handle exceptions in a proper manner.
- Try, throw and catch are the basic exception handling paradigms used.
- The general code is put in try block. It means try to execute the code.
- If the system succeeds to execute the code, execution flows in general or normal order.
- If something goes wrong while executing the try block, this code throws an exception object and stops executing code of try block.
- The error handler catches the exception object and make necessary actions needed.
- Execution continues with the next instructions following the catch block.
Example of Error Handling in JAVA
class WithExceptionHandling{
public static void main (String [ ] args) {
int a, b;
float r;
a = 7; b = 0;
try {
r = a / b;
System.out.println("Result = " + r);
}
catch (ArithmeticException e) {
System.out.println("B is zero");
}
}
}
Exception Hierarchy
The exception hierarchy is shown in the given figure:
User Defined Exceptions
- All the exceptions must inherit Throwable class.
- For runtime exception, extend RuntimeException class.
- For checked exception, extend Exception class.
Forward Engineering
- Forward engineering is the process of building from a high level model or concept to build in complexities and lower level details.
- It moves from logic implementation to the physical implementations of a system.
- It transforms a model into code through mapping to an implementation language.
- It may cause loss in information as models are semantically richer than OOP languages.
- The structural and behavioral features are clearly visualized from the model but not from raw code.
Reverse Engineering
- Reverse engineering is the process of extracting knowledge or design information from the code.
- It includes disassembling of a computer program and analyze its components and working in detail.
- It transforms code into a model through mapping from a specific implementation language.
- It is generally incomplete as the model can not be completely recreated due to information loss during forward engineering process.
Roundtrip Engineering
- Roundtrip engineering is a functionality that synchronizes two or more software artifacts like source code, models and so on.
- It is necessary when same information is present in multiple artifacts and needed to be updated.
- It has ability to synchronize existing artifacts that evolved concurrently by incrementally updating each artifact to reflect changes made to other artifacts.
Interfaces
- Interface is a concept of abstraction and encapsulation.
- It defines a set of methods that an instance of a class that has that interface.
- It declares the non private methods.
- It does not show the method implementation.
- It describes the actions that an object can do.
- No variables are allowed to be declared.
- All the functions listed must be public.
- The function description is not mentioned.
Example
public interface vehicle
{
function start_engine();
}public class car implements vehicle
{
function start_engine()
{
...................
}
}
Activity Diagram
- It models the dynamic aspects of the system.
- It is a flowchart showing flow of control from activity to activity.
- It contains activity states, transitions and objects.
- Transition may be branching, forking and joining.
Branching
- A branch have one incoming transition and two or more outgoing transitions.
- Each output transition has a boolean expression called guard expression stating condition to execute that branch.
Forking and Joining
- Fork and join are used to model concurrent processes.
- Fork represents splitting of a single flow into two or more concurrent flow of control.
- Join represents joining of concurrent flows to a single flow.
- Join and fork must balance in an activity diagram.
Swim Lanes
- To model the workflow of business process, the activity states on an activity diagram are partitioned into groups, each group representing business organization responsible for those activities.
- Each group is separated by a vertical solid line.
- Each group is known as swimlane.
Example of Activity Diagram and Swim Lanes
Q) Draw activity diagram to withdraw money from ATM. Assume necessary and suitable data.
Statechart Diagram
- It models the dynamic aspect of the system.
- It is event oriented diagram.
- It tracks the states that an object goes through.
- It shows the behavior of an individual object.
- It models the lifetime of a reactive system.
- It consists of state, event and signal.
Example of State Diagram
Q) Draw state diagram for login verification system of online banking system. Assume necessary and suitable data.
Case : Interaction Diagram
Q) Draw a sequence diagram and collaboration diagram for the given case.
A customer wants to draw money from his bank account. He enters his card in ATM. The ATM prompts
enter pin. The customer enters his pin. The ATM retrieves bank account number, encrypt pin and account
number and sends it over to the bank. The bank verifies it. If the pin is correct, ATM displays "Enter amount",
draws money from bank account and pays out the amount.
Sequence Diagram for the given case is:
Collaboration Diagram for the given case is:
Case : Use Case Diagram
Q) A patient calls clinic to make appointment for a yearly checkup. The receptionist finds nearest empty time slot in appointment book and schedules for that time slot. Draw the use case diagram for the given case.
No comments:
Post a Comment