1 FP 301 OBJECT ORIENTED PROGRAMMING FP 301
1 FP 301 OBJECT ORIENTED PROGRAMMING FP 301 Object Oriented Programming 1. 0 • Introduction To OOP 2. 0 • Fundamentals Of Java Programming Language 3. 0 • Exception Handling 4. 0 • Classes, Inheritance And Polymorphism © 2011 | PN AZRINA BINTI TAHIR
2 1. 0 INTRODUCTION TO OBJECT – ORIENTED PROGRAMMING (OOP) Understand basic object technology concept and terminology © 2011 | PN AZRINA BINTI TAHIR
3 FP 301 OBJECT ORIENTED PROGRAMMING Learning Outcome Subtopic 1. 2 1 • Define object, attribute and behavior 2 • Explain Object-Oriented Analysis and Design (OOAD) method in solving problem 3 • Understand the fundamental of Unified Modeling Language (UML) 4 • Describe general UML elements 5 • Analyze a problem using object-oriented analysis and design (OOAD) 6 • Design classes form which objects will be created using UML Class Diagram © 2011 | PN AZRINA BINTI TAHIR
4 Define Object, Attribute & Behavior FP 301 OBJECT ORIENTED PROGRAMMING • Objects ▫ Instance of a class. ▫ Can be defined as a thing. ▫ Set of attribute and behavior. • Attribute ▫ Characteristic of the object ▫ State of an object • Behavior ▫ Process or operation of the object that usually modify the state of an attribute. © 2011 | PN AZRINA BINTI TAHIR
5 Cont…. . FP 301 OBJECT ORIENTED PROGRAMMING Object Car Attribute -Color -No of tire -No of door -Chassis Operation -Driving © 2011 | PN AZRINA BINTI TAHIR
6 Object-Oriented Analysis and Design (OOAD) FP 301 OBJECT ORIENTED PROGRAMMING • Object-oriented analysis and design (OOAD) is a software engineering approach that models a system as a group of interacting objects. • Each object represents some entity of interest in the system being modeled, and is characterized by its class, its state (attribute), and its behavior. • It also can be define as a process of analyzing and designing a system from an object-oriented point of view. • Various models can be created to show the static structure, dynamic behavior, and run-time deployment of these collaborating objects. There a number of different notations for representing these models, such as the Unified Modeling Language (UML). © 2011 | PN AZRINA BINTI TAHIR
7 Object-Oriented Analysis and Design (OOAD) method in solving problem FP 301 OBJECT ORIENTED PROGRAMMING • To emphasize a problem domain and logical solution from the perspective of objects (things, concepts or entities) • OO Analysis ▫ To find and describe the objects or concepts in the problem domain. ▫ For example in the Library Information System, some of the concepts include Book, Library and Patron. • OO Design ▫ To define software objects (attributes and operations) and how they collaborate to fulfill the requirements that will be implemented in an OO programming language. ▫ For example in the Library Information System, a Book is an object that have a title as it attribute and get. Chapter as the method. • OO Programming ▫ Design components are implemented. © 2011 | PN AZRINA BINTI TAHIR
8 Fundamental of Unified Modeling Language (UML) FP 301 OBJECT ORIENTED PROGRAMMING • The Unified Modeling Language or UML is a language for specifying, visualizing, constructing and documenting the artifacts of software systems, as well as for business modeling and other non-software system. • It is also a graphical modeling language that is used to express designs. • It is a standardized language in which to specify the artifacts and components of a software system. • It is important to understand that the UML describes a notation and not a process. • It does not put forth a single method or process of design, but rather is a standardized tool that can be used in a design process. © 2011 | PN AZRINA BINTI TAHIR
9 Cont…. . FP 301 OBJECT ORIENTED PROGRAMMING • There is nine(9) diagram that can be used in UML : Diagram Description Use case diagram show actors (people or other users of the system), use cases (the scenarios when they use the system), and their relationships Class diagram The class diagram is core to object-oriented design. It describes the types of objects in the system, show classes and the relationships between them Sequence diagram show objects and a sequence of method calls they make to other objects. Collaboration diagram show objects and their relationship, putting emphasis on the objects that participate in the message exchange State diagram show states, state changes and events in an object or a part of the system Activity diagram show activities and the changes from one activity to another with the events occurring in some part of the system Component diagram show the high level programming components (such as KParts or Java Beans). Deployment diagram show the instances of the components and their relationships. Entity relationship diagram show data and the relationships and constraints between the data. © 2011 | PN AZRINA BINTI TAHIR
10 Unified Modeling Language(UML) Elements FP 301 OBJECT ORIENTED PROGRAMMING • UML offers a standard way to visualize a system's architectural blueprints, including elements such as: ▫ activities ▫ actors ▫ business processes ▫ database schemas ▫ (logical) components ▫ programming language statements ▫ reusable software components. © 2011 | PN AZRINA BINTI TAHIR
11 Analyze a problem using OOAD FP 301 OBJECT ORIENTED PROGRAMMING • To analyze a problem (case study), there will be three(3) main factor to be considered which is: ▫ Identify problem domain ▫ Identify objects ▫ Identify object attributes and operations • Example of case study: Direct. Clothing Inc. Sells shirts from their catalog. Business is growing 30 percent per year and they need a new order entry system. You have been contracted by Direct. Clothing to design the new system. Direct. Clothing produces a catalog of clothing every six months and mails it to subscribers. Each shirt in the catalog has an item identifier (ID), one or more colors (each with a different color code), one or more sizes, a description and a price. Direct. Clothing accepts cheques and credit cards. to place an order, customers can call Direct. Clothing to order directly from a customer service representative (CSR) or customers can mail or fax an order form to Direct. Clothing. © 2011 | PN AZRINA BINTI TAHIR
12 1) Identify problem domain FP 301 OBJECT ORIENTED PROGRAMMING • A problem domain is the scope of the problem that need to be solve. • For example, “Create a system allowing order entry people to enter and accept payment for an order”. © 2011 | PN AZRINA BINTI TAHIR
13 2) Identify objects • Objects can be physical or conceptual. • Object have attributes (characteristics). ▫ Size, name, shape and so on. • Object have operations (the things they can do) • Setting a value, displaying a screen or increasing speed. © 2011 | PN AZRINA BINTI TAHIR FP 301 OBJECT ORIENTED PROGRAMMING
Cont…. . © 2011 | PN AZRINA BINTI TAHIR 14 FP 301 OBJECT ORIENTED PROGRAMMING
Cont…. . 15 FP 301 OBJECT ORIENTED PROGRAMMING • Additional criteria for recognizing objects: • Relevance to the problem domain • Does the object exist within the boundaries of the problem domain? • Is the object required for the solution to be complete? • Is the object required as part of an interaction between a user and the solution? • Independent existence • For an item to be an object and not an attribute of another object, it must exist independently in the context of problem domain. • Possible objects in the Direct. Clothing case study as follow: © 2011 | PN AZRINA BINTI TAHIR
16 3) Identify object attributes and operations FP 301 OBJECT ORIENTED PROGRAMMING • Attributes are data: ▫ Order ID ▫ Customer ID Operations are action: Delete Item Change ID © 2011 | PN AZRINA BINTI TAHIR Order object
Cont…. . • Object with another object as an attribute © 2011 | PN AZRINA BINTI TAHIR 17 FP 301 OBJECT ORIENTED PROGRAMMING
Cont…. . 18 FP 301 OBJECT ORIENTED PROGRAMMING • Possible attributes and operations for objects in the Direct. Clothing, Inc. case study © 2011 | PN AZRINA BINTI TAHIR
19 Case Study Solution FP 301 OBJECT ORIENTED PROGRAMMING Order ID Date *Shirt(s) Total price *Form of payment *CSR Status Shirt ID Price Description Size Color code Customer ID Name Address Phone number Email address *Order Form of Payment Cheque number Credit card number Expiration date Catalog Shirt(s) + Calculate order ID + Calculate the total price + Add shirt to order + Remove shirt from order + Submit the order + Calculate shirt ID + Display shirt information + Assign a customer ID + Verify credit card number + Verify cheque payment + Add a shirt + Remove a shirt © 2011 | PN AZRINA BINTI TAHIR CSR Name extension
20 Design classes form using UML Class Diagram FP 301 OBJECT ORIENTED PROGRAMMING • To design a class you need to identify: ▫ Object (class name) ▫ Attributes (variables name) ▫ Operations (methods name) • Syntax: Class. Name attribute. Variable. Name [range of values] … method. Name() … © 2011 | PN AZRINA BINTI TAHIR
Cont…. . • Example: Shirt shirt. ID Price Description Size color. Code R=Red, B=Blue, G=Green calculate. Shirt. ID() display. Information() © 2011 | PN AZRINA BINTI TAHIR 21 FP 301 OBJECT ORIENTED PROGRAMMING
- Slides: 21