Sunteți pe pagina 1din 16

OBJECT ORIENTED ANALYSIS AND DESIGN

HOW DOSE OO DEVELOPMENT DIFFERS FROM THE TRADITIONAL STRUCTURED APPROACH? WHAT ARE THE NOTATIONS USED IN BOTH APPROACHES ? STRUCTURED SYSTEM ANALYSIS AND DESIGN [A]REQUIREMENT ANALYSIS 1.BASIC REQUIREMENTS FUNDAMENTAL DETAILS OF THE SYSTEM AND INFORMATION FLOW IDENTIFY DATA USED AND INFORMATION PRODUCCED DETERMINE PROCESS TIMING AND VOLUME OF DATA TO BE HANDLED IDENTIFY CONTROLS : ERROR HANDLING AND PERFORMANCE STANDARDS 2.USER TRANSACTION REQUIREMENTS WHAT INITIATES THE TRANSACTION? WHAT ARE THE SCHEDULES AND SERIALIZATION GENERATED DATA AND STORED DATA

PROCESS?

3.USER DECISION REQUIREMENTS INFORMATION USED TO MAKE THE DECISION SOURCE OF INFORMATION-TRANSACTIONS OR DATA OUTSIDE THE SYSTEM PROCESSING OF DATA TO PRODUCE REQUIRED OUTPUT 4.ORGANIZATION WIDE REQUIREMENTS MANUFACTURE PRODUCTS SATISFY THE CUSTOMERS COST BENEFIT ANALYSIS [B]FACT FINDING TECHNIQUES INTERVIEWS QUESTIONARIES RECORD REVIEW OBSERVATION [C]ANALYSIS TOOLS EER DIGRAM DATAFLOW DIAGRAM DATA DICTIONARY PROCESS CHART CASE TOOLS [D]SYSTEM DESIGN INPUT AND OUTPUT DESIGN DESIGN OF DATA STRUCTURES AND THEIR INTERACTION DESIGN OF PROCEDURES AND THEIR INTERACTION

OBJECT ORIENTED ANALYSIS AND DESIGN [A]OO DEVELOPEMENT ABSTRACTION ENCAPSULATION INHERITANCE POLYMORPHISM [B] ANALYSIS AND DESIGN PHASES ARE SIMILAR BUT SOME DISTINCTION DUE TO OO APPROACH [C] PROJECT MANAGEMENT MANAGING AN OBJECT ORIENTED DEVELOPMENT IS CONCERNED WITH THE SAME MAJOR ACTIVITIES AS MANAGING CONVENTIONAL PROJECT MANAGEMENT BUT OO HAD A VERY HIGH IMPACT ON IT.

ABSTRACTION
GENERALISED, IDEALISED MODEL OF THE OBJECT TO COPE UP WITH COMPLEXITY AN ABSTRACTION DENOTES THE ESSENTIAL CHARECTERISTICS OF AN OBJECT THAT DISTINGUISH IT FROM ALL OTHER KINDS OF OBJECTS AND THUS PROVIDE CRISPLY DEFINED CONCEPTUAL BOUNDARIES, RELATIVE TO THE PERSPECTIVE OF THE VIEWER ENTITY ABSTRACTION : AN OBJECT THAT REPRESENTS A USEFUL MODEL OF A PROBLEM DOMAIN OR SOLUTION DOMAIN ENTITY. ACTION ABSTRACTION : AN OBJECT THAT PROVIDES A GENERLISED SET OF OPERATIONS, ALL OF WHICH PERFORM THE SAME KIND OF FUNCTION VIRTUAL MACHINE ABSTRACTION : AN OBJECT THAT GROUPS TOGETHER OPERATIONS THAT ARE ALL USED BY SOME SUPERIOR LEVEL OF CONTROL OR OPERATONS THAT ALL USE SOME JUNIOR LEVEL SET OF OPERATIONS COINCIDENTAL ABSTRACTION: AN OBJECT THAT PACKAGES A SET OF OPERATIONS THAT HAVE NO RELATION TO EACH OTHER

FOR EXAMPLE 1 abstract class animal { abstract void voice(String j); // this is a abstract method .... dont have a body void walk(String g) { System.out.print("EACH ANIMAL HAS 4 LEGS " +g); } }

class cat extends animal { void voice(String j) { System.out.println("CAT SAYS ----> " + j); } } class dog extends animal { void voice(String j) { System.out.println("DOG SAYS -----> " + j); } } class clab { public static void main(String ghj[ ]) { cat c = new cat( ); // if constructor is not specified then it invokes default // constructor which has blank body c.voice("MEW MEW"); c.walk("CAT WALK"); dog d = new dog(); d.voice("BOW BOW"); d.walk("DOG RUN"); // animal a = new animal(); // abstract class can never be instantiated } }

ENCAPSULATION
ENCAPSULATION IS THE PROCESS OF COMPARTMENTALIZING THE ELEMENTS OF AN ABSTRACTION THAT CONSTITUTE ITS STRUCTURE AND BEHAVIOUR, ENCAPSULATION SERVES TO SEPARATE THE CONCEPTUAL INTERFACE OF AN ABSTRACTION AND ITS IMPLEMENTATION. IN OTHER WORDS, THE INTERNAL DETAILS OF A CLASS SHOULD BE HIDDEN FROM THE CLIENT CODE. INTERNAL DETAILS ARE HIDDEN BUT THERE IS A PUBLIC INTERFACE. FOR EXAMPLE2: BANK ACCOUNT HAS ATTRIBUTE BALANCE AND METHODS SUCH AS DEPOSIT, WITHDRAW, GETBALANCE, APPLYINTREST. THE CLIENT CODE CAN CREATE OBJECTS(INSTANCES) OF A CLASS, BUT NOT ALLOWED TO ACCESS THE INTERANAL DETAILS DIRECTLY.

CLIENT CAN MANIPULATE OBJECTS BY SENDING MESSAGES . THE ONLY MESSAGES THAT YOU CAN SEND TO A BANK ACCOUNT OBJECT ARE DEPOSIT, WITHDRAW, GETBALANCE, APPLYINTREST

WHY IS ENCAPSULATION USEFUL ? ENCAPSULATION HELPS US DEAL WITH COMLEXITY: WE KNOW HOW TO DRIVE THE CAR USING RELATIVELY HIGH LEVEL OPERATIONS SUCH AS START ENGINE, ENGAGEGEAR AND APPLY BREAKS, THE COMLEXITIES ARE ENCAPSULATED INSIDE THESE METHODS. ENCAPSULATION MAKES CODE MORE RESILIENT TO MODIFICATION. THE IMPLEMENTATION OF THE CLASS CAN BE MODIFIED WITHOUT HAVING TO CHANGE THE CLIENT CODE.

FOR EXAMPLE2: import java.io.*; class account { float balance,amount,wdraw; float rate,interest ; BufferedReader br ; InputStreamReader isr; String ams,wits; public account(float balance,float rate) { this.balance = balance ; this.rate = rate; } public void deposit() throws IOException { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); System.out.println(" "); System.out.print(" enter your amount to be deposited "); ams = br.readLine(); amount = Float.parseFloat(ams); balance = balance + amount; } public void withdraw() throws IOException { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); System.out.println(" "); System.out.print(" enter your amount to be withdrawn "); wits = br.readLine(); wdraw = Float.parseFloat(wits); if(balance>=wdraw) { balance = balance-wdraw;

System.out.println(" "+ balance); } else { System.out.println(" your balance is less than withdrawal amount"); } } public void compound() { interest = balance * rate; balance = balance + interest; } public void getbalance() { System.out.println(" "); System.out.println("current balance is " + balance); }

} class bankaccount { static BufferedReader br; static InputStreamReader isr; static String i ; static float bal,rat; static int k; public static void main(String[] tt) throws IOException { System.out.println("Before CONSTRUCTOR"); account acc = new account(100.01f,0.5f); isr = new InputStreamReader(System.in); br = new BufferedReader(isr); System.out.print("enter the value for balance ---> "); i = br.readLine(); bal = Float.parseFloat(i); acc.balance = bal ; System.out.println(" " + acc.balance) ; System.out.println(""); System.out.print("enter the value for rate ---> "); i = br.readLine(); rat = Float.parseFloat(i); acc.rate = rat; System.out.println(" " + acc.rate) ; System.out.println("enter d for deposit"); System.out.println("enter w for withdraw"); System.out.println("enter c for compound");

System.out.println("enter g for getbalance"); System.out.println("enter q for quit"); System.out.println("enter your choice :"); while((char)(k = br.read()) != 'q') { switch(k) { case 'd' : { acc.deposit(); System.out.print("enter your choice :"); break; } case 'w' : { acc.withdraw(); System.out.print("enter your choice :"); break; } case 'c' : { acc.compound(); System.out.print("enter your choice :"); break; } case 'g' : { acc.getbalance(); System.out.print("enter your choice :"); break; } } } } }

HIERARCHY
THE HIERARCHY IS A RANKING OR ORDERING OF ABSTRACTIONS EXAMLE OF HIERACHY : SINGLE INHERITANCE AND MULTIPLE INHERITANCE INHERITANCE ALLOWS COMMON FEATURES TO BE DEFINED IN A SUPERCLASS SPECIALIZED SUBCLASSES CAN BE DEFINED TO EXTEND THE SUPERCLASS

THE SUBCLASS CAN : [1] USE FEATURES OF THE SUPERCLAS [2] OVERRIDE SUPERCLASS BEHAVIOR [3] ADD NEW ATTRIBUTES AND BEHAVIOR

FOR EXAMPLE3: class publisher { String pname; publisher(String ds) { pname = ds; } } class author extends publisher { String aname; author(String s1, String s2) { super(s2); aname = s1; System.out.println("Publisher Name : " + super.pname); System.out.println("Publisher Name : " + pname); System.out.println("Author Name : " + aname); } public static void main(String s[]) { author a1 = new author ("Tata", "BBMESHRAM"); } }

EXAMPLE4: class course { String cname; int crollno; course(String s, int r) { cname = s; crollno=r; System.out.println("Course : " + crollno); System.out.println("Course : " + cname); } } class student extends course { String sname;

int rollno; student(String s, int r) { super(s,r); sname = s; rollno = r; System.out.println("Student Name : " + sname); System.out.println("Roll No : " + rollno); } public static void main(String s[]) { course c1 = new course("Java", 1); student s1 = new student("ABC", 1001); } }

WHY INHERITANCE USEFUL?


IT ENCOURAGES SOFTWARE REUSE AND HENCE GREATER PRODUCTIVITY AND QUALITY. IE CLASS DESIGNER CAN MODEL A NEW CLASS ON AN EXISTING SUPERCLASS.

POLYMORPHISM POLYMORPHISM ALLOWS THE CLIENT TO DEAL WITH LARGE INHERITANCE HIERARCHIES, THE CLIENT CAN SEND A MESSAGE TO AN OBJECT AND LEAVE THE OBJECT TO DECIDE WHAT TO DO. FOR EXAMLE: MOVE METHOD, FISH MOVE BY SWIMMING, BIRDS MOVE BY FLYING, CATS MOVE IN THEIR OWN WAY.

WHY IS POLYMORPHISM

USEFUL?

POLYMORPHISM MAKES SOFTWARE MORE EXTENSIBLE THROUGH OVERRIDING AND OVERLOADING

// in overloading , methods are overloaded in the same class; class Overload { public void method1( int a, float b) { System.out.println("int + float"); System.out.println("a=" + a); System.out.println("b=" + b);

} public void method1( float a, int b) { System.out.println("float + int"); System.out.println("a=" + a); System.out.println("b=" + b); }

public static void main(String[] s) { Overload o = new Overload(); // o.method1(5,4.5f); o.method1(5.6f,4); } }

output of the program float + int a=5 b = 4.5 float + int a = 5.6 b=4 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------class a { void show(String m) { System.out.println("class a---->"+m); } } class b extends a { void show(String m) {

System.out.println("class b--->"+m); } } class override { public static void main(String[] f) { b bb = new b(); bb.show("bbmeshram"); } } output of the program class b---bbmeshram

TYPING
A GIVEN PROGRAMMING LANGUAGE MAY BE STRONG , WEAK TYPING OR EVEN UNTYPED( OBJECT ORIENTED). IN STRONGLY TYPED LANGUAGES, VIOLATION OF TYPE CONFORMANCE CAN BE DETECTED AT THE TYPE OF COMPILATION eg;Eiffel;

C++ IS WEAKLY TYPED: VALUES OF PRIMITIVE TYPES SUCH AS INT AND FLOAT ARE INDISTINGUISHABLE WITHIN THAT TYPE; IN UNTYPED; VIOLATION OF TYPE CONFORMANCE MAY NOT BE KNOWN UNTIL EXECUTION AND MAINIFEST THEMSELVES AS EXECUTION ERRORS eg SMALLTALK STATIC BINDING: THE TYPES OF ALL VARIABLES AND EXPRESSIONS ARE FIXED AT THE TYPE OF COMPILATION

DYNAMIC BINDING: THE TYPES OF ALL VARIABLES AND EXPRESSIONS ARE NOT KNOWN UNTIL RUNTIME. class literal { public static void main(String args[]) { int n1=2000; char ch='v'; float f=2.50f; char arr[]={'r','a','j','e','s','h'}; String str="hello java"; System.out.println("The number n1 =" +n1);

System.out.println("The character ch =" +ch); System.out.println("The string str =" +str); System.out.println("The float f =" +f); for(int i=0;i<arr.length;i++) System.out.println("The char ["+i +"]="+arr[i]); } } ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package wedocto4; class protection { int n = 1; private int n_pri = 2; public int n_pub = 3; protected int n_pro = 4; public protection() { System.out.println("< base constructor >"); System.out.println("n ---> " + n); System.out.println("n_pri ---> " + n_pri); System.out.println("n_pub ---> " + n_pub); System.out.println("n_pro ---> " + n_pro); } } class derived extends protection { derived() { System.out.println("< derived constructor >"); System.out.println("n ---> " + n); // System.out.println("n_pri ---> " + n_pri); System.out.println("n_pub ---> " + n_pub); System.out.println("n_pro ---> " + n_pro); } }

class samepack { samepack() { protection q = new protection(); System.out.println("< same package constructor >" ); System.out.println("n ---> " + q.n); // System.out.println("n_pri ---> " + q.n_pri); System.out.println("n_pub ---> " + q.n_pub); System.out.println("n_pro ---> " + q.n_pro); } } class demopack { public static void main(String p[]) { protection ob1 = new protection(); derived ob2 = new derived(); samepack ob3 = new samepack(); } } -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// accessing data members by object reference w/o declaring members as static class datatypes { int i; float f; double d; byte by; String s; char c; boolean b; public void display() { System.out.println("default value of int is :" + i); System.out.println("default value of float is :" + f); System.out.println("default value of double is :" + d); System.out.println("default value of byte is :" + by); System.out.println("default value of string is :" + s); System.out.println("default value of char is :" + c); System.out.println("default value of boolean is :" + b); }

} class data1 { public static void main(String j[]) { datatypes type = new datatypes(); type.display() ; // System.out.println("default value of int is :" + type.i); // type.i // datatypes.display() ; } }

// accessing data by static reference class datatypes { static int i; static float f; static double d; static byte by; static String s; static char c; static boolean b; static public void display() { System.out.println("default value of int is :" + i); System.out.println("default value of float is :" + f); System.out.println("default value of double is :" + d); System.out.println("default value of byte is :" + by); System.out.println("default value of string is :" + s); System.out.println("default value of char is :" + c); System.out.println("default value of boolean is :" + b); } } class data { // class begins public static void main(String j[]) { // method begins

datatypes.display() ; } // method ends // // class ends

STATIC AND DYNAMIC BINDING class base { public void show() { System.out.println("method in base"); } } class derived1 extends base { public void show() { System.out.println("method in derived1"); } } class derived2 extends base { public void show() { System.out.println("method in derived2"); } public static void main(String s[]) { base b = new base(); b.show(); // b = new derived1(); derived2 d2= new derived2(); derived1 d1= new derived1(); // dd.show(); base bb; bb = d1; bb.show(); // b = new derived2(); // b.show(); bb= d2;

bb.show(); } }

PERSISTANCE
PERSISTANCE IS THE PROPERTY OF AN OBJECT THROUGH WHICH ITS EXISTANCE TRANSCENDS TIME(IE THE OBJECT CONTINUES TO EXIST AFTER ITS CREATOR CEASES TO EXIST) AND OR SPACE ( IE THE OBJECTS LOCATION MOVES FROM THE ADDRESS SPACE IN WHICH IT WAS CREATED) import java.util.*; import java.io.*; class propdemo { static Properties p , q ; static Set s; static Iterator itr; static String pkey ; static FileOutputStream fos ; static FileInputStream fin ; public static void main(String[] pp) throws IOException { p = new Properties(); p.put("1001","3000"); p.put("1002","4000"); p.put("1003","5000"); p.put("1004","6000"); p.put("1005","7000"); s = p.keySet(); itr = s.iterator(); while(itr.hasNext()) { pkey = (String)itr.next(); System.out.println("key is " + pkey + "\t " + "value is " + p.getProperty(pkey)); } /* the following process is used to store the data from property object into file */ try { fos = new FileOutputStream("bbm.dat"); p.store(fos,"ACCOUNT DATABASE"); fos.close(); } catch(ClassCastException cce) { System.out.println("ClassCastException " + cce); } bbm.dat

/* the following process is used to retrieve the data from bbm.dat file into property object ie in the program environment */ try { q = new Properties(); fin = new FileInputStream("bbm.dat"); q.load(fin); } catch(FileNotFoundException ffe) { System.out.println("FileNotFoundException " + ffe); } System.out.println("\n\n VALUES FOR q"); s = q.keySet(); itr = s.iterator(); while(itr.hasNext()) { pkey = (String)itr.next(); System.out.println("key is " + pkey + "\t " + "value is " + q.getProperty(pkey)); } } }