Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 1 CIS225 – Advanced Java Introduction to Object- Oriented Analysis and Design.

Similar presentations


Presentation on theme: "CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 1 CIS225 – Advanced Java Introduction to Object- Oriented Analysis and Design."— Presentation transcript:

1 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 1 CIS225 – Advanced Java Introduction to Object- Oriented Analysis and Design

2 Introduction This presentation introduces objects, classes, class inheritance and interfaces. You will learn the concepts of object- oriented programming. Heavy emphasis is placed on the development of software systems using the Object-Oriented Paradigm CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 2

3 Introduction The key to object-oriented programming is to model the application in terms of cooperative objects that reflect reality. You design classes that describe the behavior of these objects. Carefully designed classes are the key to a successful application. There are many levels of abstractions in system design: method abstraction, class abstraction, encapsulation, etc CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 3

4 4 Overview The Object-Oriented Paradigm The Object-Oriented Paradigm Managing Complexity with Abstraction Managing Complexity with Abstraction Building a Specification Model Building a Specification Model Finding Objects and Identifying Responsibilities Finding Objects and Identifying Responsibilities Specifying Static and Dynamic Behavior Specifying Static and Dynamic Behavior Introduction to the Unified Modeling Language Introduction to the Unified Modeling Language Introduction to Design Patterns Introduction to Design Patterns Summary Summary

5 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 5 The Object-Oriented Paradigm is defined as a “set of theories, standards, and methods that together represent a way of organizing knowledge

6 Benefits of O-O Technology Reduces the cost of software development: Provides the software developer with real- world, programmable components Provides the software developer with real- world, programmable components Provides the capability to share and reuse code with O-O techniques that reduce time to develop applications Provides the capability to share and reuse code with O-O techniques that reduce time to develop applications For example: to create a button, you simply use the JButton class to create the instance of JButton - don’t reinvent the wheel For example: to create a button, you simply use the JButton class to create the instance of JButton - don’t reinvent the wheel CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 6

7 Benefits of O-O Technology cont. Reduces the cost of software development: Provides the capability to localize and minimize the effects of modifications through programming abstraction mechanisms for faster enhancement development and provides more reliable and robust software Provides the capability to localize and minimize the effects of modifications through programming abstraction mechanisms for faster enhancement development and provides more reliable and robust software Manages complexity allow developers to address more difficult applications Manages complexity allow developers to address more difficult applications CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 7

8 8 Managing Complexity with Abstraction History In the early 1960’s, developers had two major constraints : Performance limited in processor speed the average desktop computer of today is faster than the largest machines of the60s Using less core(memory) and storage capacity- virtual memory had not been invented.

9 HistoryHistory(cont.) The programming language that we use directly influence the way that we view (model) reality. The programming language that we use directly influence the way that we view (model) reality. In the 1970s, we used the imperative programming paradigm for modeling reality- In the 1970s, we used the imperative programming paradigm for modeling reality- C, Pascal, and PL/1 – the structured method C, Pascal, and PL/1 – the structured method high degree of coupling, and poor cohesion high degree of coupling, and poor cohesion In the 1980s, we used SQL and 4GL with relational databases. We used a data-modeling paradigm entity-relationship diagrams In the 1980s, we used SQL and 4GL with relational databases. We used a data-modeling paradigm entity-relationship diagrams CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 9

10 History(cont.) In the 1990s, we used C++, Smalltalk, and Objective C -object-oriented (O-O) paradigm for modeling reality- In the 1990s, we used C++, Smalltalk, and Objective C -object-oriented (O-O) paradigm for modeling reality- The object-orientation paradigm using these languages had many limitations – high cohesion, tight coupling The object-orientation paradigm using these languages had many limitations – high cohesion, tight coupling Java now provides us with a refined version of the O-O paradigm. We have added a few new keywords and additional features and data types. Java now provides us with a refined version of the O-O paradigm. We have added a few new keywords and additional features and data types. CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 10

11 History(cont.) Most importantly, programmers now have add a modeling mechanism to view and model reality. Most importantly, programmers now have add a modeling mechanism to view and model reality. Think what it means to compute Think what it means to compute How we organize our information inside a computer system How we organize our information inside a computer system How we describe our view (model) of reality How we describe our view (model) of reality CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 11

12 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 12 The Object-Oriented Paradigm cont. Classes and Objects Classes and Objects Object-Oriented Principles Object-Oriented Principles OO Model of Computation OO Model of Computation

13 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 13 Classes A class can be viewed from four different perspectives: A class can be viewed from four different perspectives:  Modeling  Design  Implementation  Compilation

14 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 14 Classes The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them..A program is defined by using one or more classes..A program is defined by using one or more classes.

15 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 15 Classes - From a modeling perspective a class is a template for a category and defines: a class is a template for a category and defines: 1. Characteristics (attributes) - data variables 2. Services (behaviors) - methods  Its interface is the protocols used to access an object’s services and its internal state  Its implementation are the internal procedures for providing services 3. Rules and Policies – constraints that are applied 4. Relationships – peer-to-peer, hierarchical, generalization/specialization

16 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 16 Classes- From a design perspective a class is a special kind of object a class is a special kind of object It is a collection of all the objects instantiated from it It is a collection of all the objects instantiated from it It is used to create and destroy objects that belong to its collection It is used to create and destroy objects that belong to its collection It is used to hold common data and provide for group services such as: It is used to hold common data and provide for group services such as:  Find an instance  Keep averages  Hold shared information

17 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 17 Classes -From an implementation perspective a class is a “global” object with class data members and class services a class is a “global” object with class data members and class services  Applications can access the class services by using the class’ name  An application can create objects by using its constructor to “instantiate” an object  A class is used to implement the category concept in the Java programming language

18 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 18 Classes -From a compiler’s perspective the class is a programmer’s defined data type the class is a programmer’s defined data type  It is a mechanism for defining and creating runtime objects

19 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 19 The 13 O-O Basic Principles 1. Encapsulation The object contains both the data and the code to manipulate the data. A black box provides encapsulation the hiding of unimportant details The object contains both the data and the code to manipulate the data. A black box provides encapsulation the hiding of unimportant details 2. Information Hiding The object that contains the data defines the services available to other objects and hides the data and implementation details The object that contains the data defines the services available to other objects and hides the data and implementation details 3. Message Passing  An object may communicate with another object only by exchanging messages (parameters)

20 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 20 The 13 O-O Basic Principles(cont.) 4. Late Binding  The specific receiver of any given message is not known until runtime. So the determination of which method to invoke cannot be made until run time.  The virtual machine, not the compiler, selects the appropriate method.  Late binding enables us to model a real behavior of the world – Example: when a class is scheduled, it is unknown Example: when a class is scheduled, it is unknown who will attend or how many students. You only who will attend or how many students. You only know once the class begins. Gen/Spec with know once the class begins. Gen/Spec with polymorphism (#8) principle polymorphism (#8) principle

21 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 21 The 13 O-O Basic Principles(cont.) 5. Delegation 5. Delegation  Work is passed via message-passing from one object (client) to another object (agent) until it finally reaches the object that has both the data and code to perform the work –  can delegate the authority to get the work done; cannot delegate the responsibility -an example of information hiding principle  Delegation is sometimes called the perfect bureaucratic principle

22 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 22 The 13 O-O Basic Principles(cont.) 6. Class/Instance/Object Categorizing helps us to organize the complex world in which we live. All objects are instances of a class and can be created or deleted at runtime How an object provides a service is determine by the class of which the object is an instance Thus, all objects of the same class, use the same method (code) in response to a specific service request

23 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 23 The 13 O-O Principles cont. 7. Generalization/Specialization without Polymorphism  Classes can be organized by using a hierarchical inheritance structure In the structure, the specialized class (subclass) inherits the state (data fields), the behavior (set of methods), and the relationships from the superclass In the structure, the specialized class (subclass) inherits the state (data fields), the behavior (set of methods), and the relationships from the superclass  An abstract superclass is a class that is used to create only subclasses: therefore there are no direct instances of that class.

24 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 24 Abstract Class (contd.) Abstract classes are like regular classes with data and methods, but you cannot create instances (objects) of abstract classes using the new operator. An abstract method cannot be placed in a nonabstract class. If a subclass of an abstract superclass does not implement all the abstract methods, the subclass must be declared abstract.

25 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 25 Abstract Class (contd.) A classes that contains abstract methods must be abstract. However, it is possible to declare an abstract class that contains no abstract methods. A subclass can be abstract even if its superclass is concrete.

26 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 26 The 13 O-O Principles cont. 8. Generalization/Specialization with Polymorphism  The subclass inherits the attributes, relationships, prototype, and methods from the superclass that is higher in the tree.  Subclasses can create their own method to override behavior from the superclass to provide the same service.

27 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 27 The 13 O-O Principles 9. Relationships  Associations and aggregation are used to capture the collaboration between objects necessary to provide a service to a client - called a link  Types of relationships include: association, aggregation, composition, link, generalization, specialization will discuss later with examples will discuss later with examples

28 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 28 The 13 O-O Principles cont The instanceof operator can help us learn the class of an object. The instanceof operator can help us learn the class of an object. Student x = new UndergraduateStudent (); if(x instanceof UndergraduateStudent ){ System.out.println(“Mr. X is an undergraduate student”); }else{ System.out.println(“Mr. X is a graduate student”); }

29 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 29 The 13 O-O Principles cont 10. Interface/Instance/Object 10. Interface/Instance/Object  All objects that implement an interface are instances of that interface  Interfaces define types  Instances of an interface cannot be created (instantiated) or destroyed (deleted) as an instance interface.  Each must be created or destroyed as an instance of the class to which it is a member.

30 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 30 The 13 O-O Principles cont 11. Generalization/Specialization of Interfaces  Interfaces can be organized by using a hierarchical inheritance structure  The specialized interface inherits the service protocol from the generalized interfaces that are higher in the (tree) structure.

31 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 31 The 13 O-O Principles cont 12. Reflection 12. Reflection  Each object knows detailed information about the classes and interfaces of which it is an instance  This means that an application can at runtime acquire detail information about the object from the object itself.

32 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 32 The 13 O-O Principles cont 12. Reflection cont’d. ways: 12. Reflection cont’d. ways: 1. Determine the class of the object 2. Get info about a class’s modifiers, member variables, methods, constructors, and superclass 3. Find out what constants and method declarations belong to an interface 4. Create an instance of a class whose name is not known until runtime

33 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 33 The 13 O-O Principles cont 12. Reflection cont’d. ways: 12. Reflection cont’d. ways: 5. Get and set the value of an object’s field, even if the field name is not known to your program until run time. 6. Invoke a method on an object, even if the method is not known until runtime. 7. Create a new array, whose size and component type are not known until runtime, and then modify the array’s components.

34 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 34 The 13 O-O Principles cont 12. Reflection cont’d. 12. Reflection cont’d. To make your programs easier to debug and maintain do not use Method objects. To make your programs easier to debug and maintain do not use Method objects. Instead use interfaces and then implement them in the class that performs the needed action in the class that performs the needed action

35 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 35 The 13 O-O Principles cont 13. Multithreading 13. Multithreading  Each object can have concurrent execution paths This means that an object can handle multiple events (or service requests) in a concurrent manner) This means that an object can handle multiple events (or service requests) in a concurrent manner)

36 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 36 Refactoring Martin Fowler coined this term for restructuring code in a Disciplined way –make small transformation to your code Example (From): Car Shape selected setSelected isSelected HouseShape selected setSelected isSelected SelectableShape selected setSelected isSelected CarShape HouseShape To:

37 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 37 O-O Paradigm -Objects An object is the most fundamental concept/mechanism of O-O programming An object is the most fundamental concept/mechanism of O-O programming There are three different ways of looking at objects: There are three different ways of looking at objects:  Application modeling view  Design modeling view  Formal viewpoint

38 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 38 Objects - From an application modeling view An object has the following components: An object has the following components: 1. Characteristics – internal information that describes the object (attribute name and value) 2. Services (behaviors)– a collection of services that has some semantic meaning sometimes called a protocol a. interface (prototype internal information) a. interface (prototype internal information) b. implementation (method) b. implementation (method) 3. Unique Identifier – Each object is given a unique ID at creation and cannot be changed. Usually the machine id number plus the time in milliseconds -

39 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 39 Objects - From an application modeling view cont. An object has the following components: An object has the following components: 4. Rules and Policies – establish constraints which are applied to the object 5. Relationships – how objects stand in relations with other objects peer-to-peer or hierarchical

40 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 40 Objects From a design modeling view an object: From a design modeling view an object: 1. Is an example (instance) of a category (class) form a hierarchy of gen/spec 2. May be an example of a type (interface) A type is a collection of service declaration (service name, arguments, return type and exception thrown) with no implementation code A type is a collection of service declaration (service name, arguments, return type and exception thrown) with no implementation code 3. May be a “metaclass” object- may have attributes, services, object relationships, and rules; however may not be in a gen/spec relationship

41 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 41 Objects From a design modeling view an object cont. : From a design modeling view an object cont. : 4. Is created by a category (class) object 5. Can communicate either synchronous (method invocation) or asynchronous (event generation) with other objects 6. Can be “persistently” associated with another object in either a peer-to-peer or hierarchical relationship

42 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 42 Objects From a formal perspective an object is defined by: From a formal perspective an object is defined by:  Its responsibilities – the value that it adds to the system  Its rule set – -Attribute Assertions: Range, Enumeration, -Attribute Assertions: Range, Enumeration, and Type constraints and Type constraints - Operation Assertions: Pre- and Post- and - Operation Assertions: Pre- and Post- and invariance conditions invariance conditions - Class invariance: A logical statement(s) - Class invariance: A logical statement(s) about the object that must be true at all about the object that must be true at all times times

43 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 43 Objects cont. From a formal perspective an object is defined by: From a formal perspective an object is defined by:  Its rule set(cont’d): - inference engines –resolve multiple - inference engines –resolve multiple inheritance conflicts inheritance conflicts  Its classification –must be in some category (class) even if it is a category of one object  Its type(s). An object may implement the services of any specific type w/o being constrained it its implementation of the services  Its relationships with other objects peer-to-peer or hierarchical

44 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 44 OO Model of Computation The problem-solving view of OO programming is different from the pigeonhole model used with imperative programming The problem-solving view of OO programming is different from the pigeonhole model used with imperative programming OO use terms like object, class, and services instead of terms like assignments, variables or memory addresses OO use terms like object, class, and services instead of terms like assignments, variables or memory addresses

45 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 45 OO Model of Computation OO uses a community of helpers that work together to solve the problem OO uses a community of helpers that work together to solve the problem OO programming uses a simulation model of computation OO programming uses a simulation model of computation  We define objects in the problem domain that will help us solve the problem  We define how these objects interact with one another and then set them in motion

46 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 46 Managing Complexity with Abstraction

47 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 47 Managing Complexity with Abstraction Complex Systems Complex Systems Abstraction Mechanisms Abstraction Mechanisms Service Activation Abstractions Service Activation Abstractions Process Control Abstractions Process Control Abstractions Relationships Relationships Rules Rules

48 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 48 Complex Systems Much of the complexity of imperative programming stems from the high degree of coupling and poor cohesion makes the systems inflexible and unmaintainable Much of the complexity of imperative programming stems from the high degree of coupling and poor cohesion makes the systems inflexible and unmaintainable  Coupling – the dependence of one piece of code on either another section of code and/or some data storage

49 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 49 Complex Systems  Cohesion – how well a set of code and its associated data fit together  A class should describe a single entity, and all the class operations (methods) should fit together to support a coherent purpose  We can use a class for students. We should not include student and staff in the same class because students and staff have different entities.

50 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 50 Complex Systems Consistency  Follow standard Java programming style and naming conventions.  Choose informative names for classes, data fields, and methods  A popular style is to place the data declaration before the constructor, and place constructors before methods. See UML Class and Object diagram.doc in folder UML Folder

51 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 51 Complex Systems Complex systems tend to have five key attributes: Complex systems tend to have five key attributes: 1.Complex systems take on the form of a hierarchy 2.The choice of which system components are considered primitive is arbitrary 3.Intracomponent links are usually stronger than intercomponent links 4.Hierarchical systems are usually composed of a few different kinds of subsystems combined or arranged in various ways 5.A good complex system has usually evolved from a good simple system

52 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 52 System Development is modeling The development of a large system is a modeling activity in which a series of increasingly detailed models is developed The development of a large system is a modeling activity in which a series of increasingly detailed models is developed The different types of models include: The different types of models include:  Specification model – a black box model of the system in terms of business value provided by it  Analysis model – a model that demonstrates how the specification model will be realized  Design model – a description of how the analysis model will be coded  Code model – an implementation of the design model which upon compilation and execution provides a solution to the business problem.

53 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 53 System Development There are different software development processes that can be used to control the activities and level of detail while developing complex systems There are different software development processes that can be used to control the activities and level of detail while developing complex systems  Waterfall process model  Iterative process model  Divide-and-Conquer (Functional Decomposition)  The Object-oriented approach

54 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 54 System Development cont. Waterfall process model Waterfall process model develops each system model develops each system model sequentially and describes the later sequentially and describes the later activities associated with testing, activities associated with testing, delivery, and maintenance. Each delivery, and maintenance. Each phase is completed before any work phase is completed before any work is started on the next phase. is started on the next phase.  Iterative process model (rapid programming) iteratively develop all of the models cycling through the phases

55 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 55 System Development cont.  Divide-and-Conquer (Functional Decomposition) Take a big problem and break it into a number of smaller problems Take a big problem and break it into a number of smaller problems  The Object-oriented approach Breaks a complex system into component Breaks a complex system into component parts in the form of objects and the parts in the form of objects and the relationships among them relationships among them

56 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 56 Abstraction Mechanisms The history of software development is marked by the introduction of successively more abstract mechanisms that give developers better tools to manage complexity. These include: The history of software development is marked by the introduction of successively more abstract mechanisms that give developers better tools to manage complexity. These include:  Type abstractions  Service activation abstractions  Processing control abstractions  Relationships abstractions  Behaviors  Rules

57 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 57 Type Abstractions Object-oriented abstraction mechanisms are a natural progression of abstracting from functions and simple data types to modules and abstract data types and then to objects Object-oriented abstraction mechanisms are a natural progression of abstracting from functions and simple data types to modules and abstract data types and then to objects The concept of an object is the merging of two separate concepts: data types and functions The concept of an object is the merging of two separate concepts: data types and functions

58 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 58 Evolution of Data Abstraction Basic Data Types Functions Modules Abstract Data Types (ADT) Objects (instances) Class (category) Class with Gen/Spec (inheritance) Polymorphism (overriding, overloading) Interface (type) Class with Reflection (RTTI)

59 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 59 Abstractions Mechanisms -Basic Data Types Early assembly language programmers had only very basic data types- basic integer, floating point number, and character were the core data type Early assembly language programmers had only very basic data types- basic integer, floating point number, and character were the core data type Early programming language extended the core set to include arrays and extended precision versions of these data types Early programming language extended the core set to include arrays and extended precision versions of these data types

60 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 60 Type Abstractions Basic data types Basic data types Abstract data types Abstract data types Functions Functions Modules Modules Objects Objects Class Class Class with generalization/specialization Class with generalization/specialization Polymorphism Polymorphism Interface Interface Reflection Reflection

61 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 61 Service Activation Abstractions Abstractions that identify the mechanisms by which data processing is activated to achieve business value Abstractions that identify the mechanisms by which data processing is activated to achieve business value  Function Call  Event Processing (Asynchronous communication)  Message Passing (Synchronous communication)  Subscription (Asynchronous communication)

62 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 62 Processing Control Abstractions There are several traditional processing control abstractions that have been incorporated into object-oriented approaches: There are several traditional processing control abstractions that have been incorporated into object-oriented approaches:  Single Program Execution  Multitasking  Sequential Execution  Multithreading

63 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 63 Relationships Prior to the introduction of the object and class abstractions, it was very difficult to capture information about the relationships between data items Prior to the introduction of the object and class abstractions, it was very difficult to capture information about the relationships between data items  Generalization/specialization (gen/spec) is a relationship between classes  Associations and aggregations are relationships between objects  Behavior relationships permit both classes and objects to be organized using either gen/spec or association and aggregation

64 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 64 Association Describes a group of links with common structure and semantics Describes a group of links with common structure and semantics  Common semantics implies that the services provided by each object in the same class are the same, but they may be polymorphic All links in an association must connect objects from the same class to objects from a second class All links in an association must connect objects from the same class to objects from a second class Associations are bidirectional and may be binary, ternary, or higher Associations are bidirectional and may be binary, ternary, or higher Association is a “weak” relationship Association is a “weak” relationship

65 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 65 Association Association represents a general binary relationship that describes an activity between two classes. Association represents a general binary relationship that describes an activity between two classes. An association is usually represented as a data field in the class. An association is usually represented as a data field in the class.

66 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 66 Representing Association in Classes An association is usually represented as a data field in the class.

67 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 67 Aggregation Aggregation is a special form of association, which represents an ownership relationship between two classes. Aggregation models the relationship like has-a, part-of, owns, and employed-by. Aggregation is a special form of association, which represents an ownership relationship between two classes. Aggregation models the relationship like has-a, part-of, owns, and employed-by.

68 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 68 Aggregation An object that represents the whole is associated with a set of objects that represent its components An object that represents the whole is associated with a set of objects that represent its components Aggregation is both transitive and antisymmetric Aggregation is both transitive and antisymmetric The components must be from the same semantic domain (“composed of” not “made of”) The components must be from the same semantic domain (“composed of” not “made of”)

69 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 69 Composition An Object maybe owned by several other aggregating objects An Object maybe owned by several other aggregating objects If an object is exclusively owed by an aggregating object the relationship is called CompositionIf an object is exclusively owed by an aggregating object the relationship is called Composition Example:Example: “A Student has a Name” is Composition relationship“A Student has a Name” is Composition relationship “A Student has an Address” is an Aggregation relationship“A Student has an Address” is an Aggregation relationship

70 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 70 Composition vs. Aggregation Composition is a “strong” association Aggregation is a “weak” association

71 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 71 Behavior Behavioral relationship mechanisms provide a way to organize objects and classes in either peer- to-peer (association) or hierarchical (gen/spec and aggregation) structures Behavioral relationship mechanisms provide a way to organize objects and classes in either peer- to-peer (association) or hierarchical (gen/spec and aggregation) structures Behavioral analysis is the process of looking at how each object (class) provides its services Behavioral analysis is the process of looking at how each object (class) provides its services In static behavior the operations in the method will not be affected by external or internal events In static behavior the operations in the method will not be affected by external or internal events With dynamic behaviors, the current state of an object determines its behavior With dynamic behaviors, the current state of an object determines its behavior

72 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 72 Rules Relationships are mechanisms for specifying data semantics Relationships are mechanisms for specifying data semantics Static and dynamic behaviors capture a system’s procedural semantics Static and dynamic behaviors capture a system’s procedural semantics Rules are used to capture a systems declarative semantics Rules are used to capture a systems declarative semantics Declarative semantics address the issues of global control description and business rules Declarative semantics address the issues of global control description and business rules  Control rules  Business rules  Exception handling rules  Contention rules  Triggers

73 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 73 Building a Specification Model

74 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 74 Building a Specification Model The OO way of modeling reality does not try to organize all of reality The OO way of modeling reality does not try to organize all of reality We usually try to model only the relevant features of a specific application domain We usually try to model only the relevant features of a specific application domain One way of bounding the domain is to use Use Cases One way of bounding the domain is to use Use Cases Uses cases capture the functional requirements and business-value propositions of a proposed system along with the high- level processes needed to achieve those propositions Uses cases capture the functional requirements and business-value propositions of a proposed system along with the high- level processes needed to achieve those propositions

75 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 75 Building a Specification Model A use case: A use case:  Specifies a sequence of actions, including variants, that a system performs and that yields an observable result of value to an actor  Is a description of all the possible sequences of interactions among the system and one or more actors in response to some initial stimulus by one of the actors  Is a collection of possible sequences of interactions between the system under discussion and its external actors, related to a particular goal

76 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 76 Use Cases Uses cases are concerned with the actors and the sequences of interactions between them Uses cases are concerned with the actors and the sequences of interactions between them Some important concepts include: Some important concepts include:  The goal - the business value to the user  The system - the application  An actor – external entity that interacts with the system  Use case – describes an interaction that achieves a goal for an actor  Use-case bundle – a collection of highly correlated use cases

77 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 77 Use Cases The Goal The Goal  Use cases attempt to capture the value propositions from an external view  The goal is to capture the business value of the system from the user’s perspective The System The System  Usually viewed as a “black-box”

78 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 78 Use Cases The Actors The Actors  Uses cases divide the world into two parts: the system and the users (external entities that use it)  Actors are a way of categorizing system users who share a set of common interactions to achieve a goal  An actor represents an external entity that can initiate actions or receive requests from the system  A specific user is an instance of an actor  The set of requests/responses from/to the actors represents the system boundaries

79 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 79 Use Cases Use Case and Scenario Use Case and Scenario  A use case describes a system in terms of sequences of interactions between various actors and the system  A scenario is a short narrative that outlines a sequence of requests and responses between a user and the system -“what happens next”  A scenario describes how a user will use the system to achieve a goal  A use case is the generalized form of a family of scenarios  A scenario is a specific instance of a use case

80 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 80 Use Cases The Use Case describes The Use Case describes  The pre-conditions that must exist for it to be valid  The post-conditions that define the state of the system after the use case is concluded  Detailed business logic that is performed (technology independent)  Business exceptions that can occur  Business constraints that apply to the system when reacting to a specific user request

81 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 81 Use Cases To effectively capture the functional aspects of a system the description of the system must be kept at a consistent level of abstraction To effectively capture the functional aspects of a system the description of the system must be kept at a consistent level of abstraction To successfully develop use cases we must know the dimension of the functional description we are trying to capture To successfully develop use cases we must know the dimension of the functional description we are trying to capture These dimensions include: These dimensions include:  High-level and low-level  Primary and secondary  Essential and concrete

82 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 82 Use Cases High-level functional descriptions High-level functional descriptions  Provide general and brief descriptions of the essence of the business values provided by the system Low-level functional descriptions Low-level functional descriptions  Provide details showing the exact order of activities, tasks, or alternatives

83 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 83 Use Cases Primary functions Primary functions  Describe the essential functionality provided to the user Secondary functions Secondary functions  Deal with rare and exceptional cases Essential functions Essential functions  Describe business solutions that are independent of implementation (hardware and software black- box) Concrete functions Concrete functions  Describe use cases that are design dependent (clear-box)

84 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 84 Drop Course Register Add CourseDelete CourseCancel Course Course Registration System StudentAdminProf High-level, primary, essential use case diagram

85 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 85 Finding Objects and Identifying Responsibilities

86 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 86 Finding Objects and Identifying Responsibilities When we analyze systems, we create models of the application domain of interest When we analyze systems, we create models of the application domain of interest Although much simpler than reality, if the model is rich enough it can help us understand the business reality and manage complexity Although much simpler than reality, if the model is rich enough it can help us understand the business reality and manage complexity

87 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 87 Finding Objects and Identifying Responsibilities With OO analysis we model reality with objects as building blocks With OO analysis we model reality with objects as building blocks We describe our world using object categories (classes) or object types (interfaces) We describe our world using object categories (classes) or object types (interfaces) We assign service prototypes to interfaces We assign service prototypes to interfaces We assign attributes and services to categories We assign attributes and services to categories

88 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 88 Finding Objects and Identifying Responsibilities We define relationships between classes (gen-spec, agg-comp, links) We define relationships between classes (gen-spec, agg-comp, links) Interfaces can be organized using generalization/specialization Interfaces can be organized using generalization/specialization The description of service methods is captured by pseudocode or UML The description of service methods is captured by pseudocode or UML The behavior of the system is modeled as a sequence of messages sent between objects that are instances of the categories or types The behavior of the system is modeled as a sequence of messages sent between objects that are instances of the categories or types

89 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 89 Finding Objects and Identifying Responsibilities The final OO model should: The final OO model should:  Organize the data into objects and classes and give the data a structure via relationships (gen/spec, agg/comp, links)  Organize the services into conceptual groups via classes or interfaces  Specify local functional behaviors  Capture control or global behavior  Capture constraints

90 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 90 Finding Objects and Identifying Responsibilities Two views on how objects come into being: empiricist and phenomenalist Two views on how objects come into being: empiricist and phenomenalist Empiricist Empiricist  Objects exist already and are waiting to be perceived  Developers are blind to existing objects due to their reliance on functional decomposition Phenomenalist Phenomenalist  Objects come from the world and our consciousness via a dialectical process  Real-world objects are a reflection of social relations and the human thinking process

91 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 91 Finding Objects and Identifying Responsibilities Objects can be identified as use cases are written Objects can be identified as use cases are written Steps to finding objects: Steps to finding objects:  Obtain a narrative or informal description of the problem  Use the nouns, pronouns, and noun phrases to identify objects, categories and types  Use verbs and predicate phrases to identify services

92 CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 92 Summary The Object-Oriented Paradigm The Object-Oriented Paradigm Managing Complexity with Abstraction Managing Complexity with Abstraction Specification Models Specification Models Objects and Responsibilities Objects and Responsibilities Static and Dynamic Behavior Static and Dynamic Behavior The Unified Modeling Language The Unified Modeling Language Design Patterns Design Patterns


Download ppt "CIS225 - Advanced Java Richard C. Lee and William M. Tepfenhart 1 CIS225 – Advanced Java Introduction to Object- Oriented Analysis and Design."

Similar presentations


Ads by Google