Presentation is loading. Please wait.

Presentation is loading. Please wait.

9 - Class & Method Design Model Enhancement Design to Code Proposal Presentation.

Similar presentations


Presentation on theme: "9 - Class & Method Design Model Enhancement Design to Code Proposal Presentation."— Presentation transcript:

1 9 - Class & Method Design Model Enhancement Design to Code Proposal Presentation

2 Class & Method Design Criteria, activities, & techniques used to design classes & methods Part of Design Phase where work is actually accomplished Refinement of UML models to create the most efficient system possible that still meets the users’ requirements The steps just before the actual coding of the system

3 Review of Terms Object – basic building block of a system; instances of classes Class – defines both data & processes that each object contains Attributes – describe data about the object Methods – specify processes that objects can perform Message – procedural call from one object to another

4 More Terms Inheritance – superior classes pass attributes & methods to subordinate classes Encapsulation – combining processes & data into a single object Information Hiding – only information required to use an object should be available outside of an object Polymorphism – same message is interpreted differently by different objects Dynamic binding – interpretation of message by an object takes place at run time

5 New Terms Cohesion – how specific a module is within a system (i.e., a class or object should represent only one thing) Coupling – level of interdependence among modules (classes, objects, & methods) in a system The higher the degree of coupling, the more likely that changes in part of a system will require changes in other parts Connascence – two modules are so intertwined that a change in one requires a change in the other Ideally, a system should have high Cohesion and low (i.e., loose) Coupling

6 Opportunities for Reuse Class Library Set of implemented classes that are designed for reuse Pre-built “template” classes with Attributes and Methods already defined Can be utilized using Inheritance Support Foundation Layer Component Self-contained piece of software that can be “plugged” into a system Simplify development of objects on Problem Domain & Human- Computer Interaction Layers

7 Optimizing the Design 1. Shorten/simplify paths between objects 2. Move attributes to provide more direct access 3. Reduce the number of messages (Fan-out) sent by an object 4. Reorder execution of statements 5. Cache (temporarily save) computational results

8 Constraints & Contracts Contract Formalizes the interactions between client and server objects Document the message passing between objects Contain information necessary for programmer to understand method Contracts may contain: Pre-conditions – constraints that must be met for a method to execute Post-conditions – constraints that must be met after the method executes (or method is undone)

9 Contract Example Method Name: Class Name:ID: Clients (Consumers): Associated Use Cases: Description of Responsibilities: Arguments Received: Type of Value Returned: Pre-Conditions: Post-Conditions:

10 Method Specification Method Specifications – written documents that include explicit instructions on how to write the code to implement a method No standard syntax for Method Specification Written in Structured English – short sentences 4 Components: 1. General Information about Method 2. Events – items that trigger method 3. Message Passing – what is being passed, and returned 4. Algorithm Specification (calculations, formula, etc.)

11 From class diagram to code Attributes are generally implemented as instance variables. Choose an appropriate class, but normally it will be a class from the standard Java library such as String. Generalizations are implemented using the extends keyword, and interfaces are implemented using the implements keyword. Associations are normally implemented using instance variables. Divide each two-way association into two one-way associations so that each associated class has an instance variable representing the other end of the association. One-way association where the multiplicity at the other end is ‘one’ or ‘optional’, you declare a variable whose type is that class To implement a one-way association where the multiplicity at the other end is ‘many’, use a collection class such as ArrayList. To implement an association where the multiplicity at the other end has a small, fixed upper bound, use a regular array

12 class Car { private String carColor; private double carPrice = 0.0; public String getCarColor(String model) { return carColor; } public double getCarPrice(String model) { return carPrice; }

13 public class Employee { private static String department = "R&D"; private int empId; private Employee(int employeeId) { this.empId = employeeId; } public static String getEmployee(int emplId) { if (emplId == 1) { return "idiotechie"; } else { return "Employee not found"; } public static String getDepartment() { return department; }

14 public class Customer { private String name; private String address; private String contactNumber; } public class Car { private String modelNumber; private Customer owner; }

15 public class Customer { private String name; private String address; private String contactNumber; private Car car; } public class Car { private String modelNumber; private Customer owner; }

16 public class Car { private String brand; public Car(String brands){ this.brand = brands; } public Car() { } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public class Customer { private Car[] vehicles; ArrayList carList = new ArrayList (); public Customer(){ vehicles = new Car[2]; vehicles[0] = new Car("Audi"); vehicles[1] = new Car("Mercedes"); carList.add(new Car("BMW")); carList.add(new Car("Chevy")); }

17 public class Car { private String model; public void printPrice() { } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public class hatchback extends Car { private String model; public void printPrice() { System.out.println("Hatchback Price"); } public String getModel() { return model; } public void setModel(String model) { this.model = model; }

18 public class PaymentSystem { } public class Order { public void processPayment(PaymentSystem ps){ } dependecy

19 public class Student { } public class School { private Student student; }

20 public class Employee { } public class Company { private Employee[] employee; }

21 Proposal Presentation


Download ppt "9 - Class & Method Design Model Enhancement Design to Code Proposal Presentation."

Similar presentations


Ads by Google