Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-oriented analysis (OOA) techniques are used to (1) study existing objects to see if they can be reused or adapted for new uses, and (2) define new.

Similar presentations


Presentation on theme: "Object-oriented analysis (OOA) techniques are used to (1) study existing objects to see if they can be reused or adapted for new uses, and (2) define new."— Presentation transcript:

1 Object-oriented analysis (OOA) techniques are used to (1) study existing objects to see if they can be reused or adapted for new uses, and (2) define new or modified objects that will be combined with existing objects into a useful business computing application. Object modeling is a technique for identifying objects within the systems environment and the relationships between those objects. Classes and Objects

2 An object is something that is or is capable of being seen, touched, or otherwise sensed, and about which users store data and associate behavior. Attributes are the data that represent characteristics of interest about an object.

3 An instance (or object instance) of an object consists of the values for the attributes that describe a specific person, place, thing, or event. 412209:Customer customer number = 412209 last name =Bentley first name =Lonnie home phone =317-463-9593 street =2625 Darwin Dr. city =West Lafayette state =Indiana zipcode =47906 etc. 0256101329: Book ISBN = 0256101329 type = textbook title = Systems Analysis & Design Methods copyright = 1996 0256102219: Book ISBN = 0256102219 type = workbook title = Projects and Cases to Accompany SADM copyright = 1996 (a) (b)

4 Behavior refers to those things that the object can do and which correspond to functions that act on the object’s data (or attributes). –In object-oriented circles, an object’s behavior is commonly referred to as a method or service. Encapsulation is the packaging of several items together into one unit.

5 A Simple Class public class Greeter { public String sayHello() { String message ="Hello,World!"; return message; } }

6 Method Definition  access specifier (such as public)  return type (such as String or void)  method name (such as sayHello)  list of parameters (empty for sayHello)  method body in { }

7 Method Parameters public class Rectangle {... public void translate(int x, int y) { method body }... }

8 Syntax 2.4: Method Implementation public class ClassName {... accessSpecifier returnType methodName(parameterType parameterName,...) { method body }... } …Continue

9 …Continue –Example: public class Greeter { public String sayHello() { String message ="Hello,World!"; return message; } } –Purpose: To define the behavior of a method A method definition specifies the method name, parameters, and the statements for carrying out the method's actions

10 Syntax 2.5: The return Statement return expression; or return; –Example: return message; –Purpose: To specify the value that a method returns, and exit the method immediately. The return value becomes the value of the method call expression.

11 Testing a Class  Test class: a class with a main method that contains statements to test another class.  Typically carries out the following steps: »Construct one or more objects of the class that is being tested. »Invoke one or more methods. »Print out one or more results

12 A Test Class for the Greeter Class public class GreeterTest { public static void main(String [] args)) { Greeter worldGreeter = new Greeter(); System.out.println(worldGreeter.sayHello() ); }

13 Building a Test Program 1. Make a new subfolder for your program. 2.Make two files, one for each class. 3.Compile both files. 4.Run the test program.

14 Instance Fields public class Greeter {... private String name; }  access specifier (such as private)  type of variable (such as String)  name of variable (such as name)

15 Instance Fields

16 Accessing Instance Fields  The sayHello method of the Greeter class can access the private instance field: public String sayHello() { String message = "Hello, " + name + "!"; return message; }

17  Other methods cannot: public class GreeterTest { public static void main(String[] args) {... System.out.println(daveGreeter. name); // ERROR } }  Encapsulation = Hiding data and providing access through methods

18 Syntax 2.6 : Instance Field Declaration accessSpecifier class ClassName {... accessSpecifier fieldType fieldName;... }

19 –Example: public class Greeter {... private String name;... } –Purpose: To define a field that is present in every object of a class

20 Constructors  A constructor initializes the instance variables  Constructor name = class name –public class Greeter() { public Greeter(String aName) { name = aName; }... }  Invoked in new expression new Greeter("Dave")

21 Syntax 2.7 : Constructor Implementation accessSpecifier class ClassName {... accessSpecifier ClassName(parameterType parameterName...) { constructor implementation }... }

22 –Example: public class Greeter {... public Greeter(String aName) { name = aName; }... } –Purpose: To define the behavior of a constructor, which is used to initialize the instance fields of newly created objects

23 File Greeter.java 1 public class Greeter 2 { 3 public Greeter(String aName) 4 { 5 name = aName; 6 } 7 8 public String sayHello() 9 {

24 10 String message = "Hello, " + name + "!"; 11 return message; 12 } 13 14 private String name; 15 }

25 File GreeterTest.java 1 public class GreeterTest 2 { 3 public static void main(String[] args) 4 { 5 Greeter worldGreeter = new Greeter("World"); 6System.out.println(worldGreeter.sayHe llo()); 7

26 8 Greeter daveGreeter = new Greeter("Dave"); 9System.out.println(daveGreeter.s ayHello()); 10 } 11 }

27 A class is a set of objects that share common attributes and behavior. A class is sometimes referred to as an object class. Open() Close() ISBN type title copyright Book Customer customer number last name first name home phone street city state zipcode etc. changeAddress()

28 Inheritance means that methods and/or attributes defined in an object class can be inherited or reused by another object class. Generalization/specialization is a technique wherein the attributes and behaviors that are common to several types of object classes are grouped into their own class, called a supertype. The attributes and methods of the supertype object class are then inherited by those object classes.

29 A message is passed when one object invokes one or more of another object's methods (behaviors) to request information or some action Customer add order modify order delete order display status etc. order number order date order status etc. Order display order status of order 23161 MESSAGE REQUEST (containing name of request behavior and attribute needed by ORDER)

30 Polymorphism means “many forms.” Applied to object-oriented techniques, it means that a behavior may be completed differently for different objects/classes.


Download ppt "Object-oriented analysis (OOA) techniques are used to (1) study existing objects to see if they can be reused or adapted for new uses, and (2) define new."

Similar presentations


Ads by Google