Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms.

Similar presentations


Presentation on theme: "COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms."— Presentation transcript:

1 COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms

2 Objectives Learn about the software life cycle Learn how to discover new classes and methods Understand the use of CRC cards for class discovery Be able to identify inheritance, aggregation, and dependency relationships between classes

3 Objectives (cont’d) Learn to use UML class diagrams to describe class relationships Learn how to use object-oriented design to build complex programs Learn how to analyze the efficiency of an algorithm

4 Software Life Cycle Encompasses all activities from initial analysis until obsolescence Formal process for software development –Describes phases of the development process –Gives guidelines for how to carry out the phases

5 Development Process AnalysisDesignImplementationTestingDeployment

6 Analysis Phase Defines what the project is suppose to do Not concerned with how the program will accomplish tasks What is the output of the Analysis Phase?

7 Design Phase Plans system implementation Identifies Classes, Methods Needed What is the output of the Design phase?

8 Implementation Phase Write and compile the code Implement classes and methods discovered in the design phase Output?

9 Testing Phase Run tests to verify the program works correctly Output: a report of the tests and their results, test coverage

10 Deployment Phase Software installed and used for its intended purpose

11 The Waterfall Model

12 Sequential process of analysis, design, implementation, testing, and deployment When rigidly applied, does not work well!

13 The Spiral Model Breaks development process down into multiple phases Early phases focus on the construction of prototypes Lessons learned from development of one prototype can be applied to the next iteration Problem: can lead to many iterations, and process can take too long to complete

14 The Spiral Model

15 Extreme Programming Strives for simplicity Removes formal structure Focuses on best practices Realistic planning Small releases MetaphorSimplicityTestingRe-factoring

16 Extreme Programming (cont’d) Focuses on best practices –Pair programming –Collective ownership –Continuous integration –40-hour week –On-site customer –Coding standards

17 Test Driven Development

18 Typical Sequence of Steps: –Create a new test case –Write enough code to fail the test –Run the tests and watch the new test fail –Write the simplest code that will pass the new test –Run the tests and watch all the tests pass –Remove duplication –Rerun the tests

19 Test Driven Development

20 Discovering Classes Class represents set of objects with the same behavior –Entities with multiple occurrences in problem description are good candidates for objects –Identify commonalities –Design classes to capture commonalities Represent some entities as objects, others as primitive types –Should we make a class Address or use a String? Not all classes can be discovered in analysis phase Some classes may already exist?

21 CRC Cards Class, Responsibility, Collaboration Used to start brainstorming about an object-oriented design Responsibilities are operations performed by the class Collaborators are other classes involved in performing these operations

22 CRC Cards (cont’d)

23 Relationships Between Classes InheritanceAggregationDependency

24 Inheritance Is-a relationship Relationship between a more general class (superclass) and a more specialized class (subclass) Example: Every savings account is a bank account Can be overused: Should a Tire be a subclass of Circle? Design Principle: Favor composition over inheritance

25 Aggregation Has-a relationship Objects of one class contain references to objects of another class Use an instance variable A tire has a circle as its boundary: class Tire {... private String rating; private Circle boundary; }

26 Aggregation (cont’d) Every car has a tire (in fact, it has multiple tires) class Car extends Vehicle {... private Tire[] tires; }

27 UML Notation

28 Dependency Uses relationship Example: Many applications depend on the Scanner class to read input Aggregation is a stronger form of Dependency BlueJ only shows Uses relationships

29 UML Diagram Example

30 Class Diagram - BlueJ

31 Five-Part Development Process Gather requirements Use CRC cards to find classes, responsibilities, and collaborators Use UML diagrams to record class relationships Use javadoc to document method behavior Implement your classes

32 Discussion Questions? How does this development process apply to your lab assignments? –Gather requirements –Use CRC cards to find classes, responsibilities, and collaborators –Use UML diagrams to record class relationships –Use javadoc to document method behavior –Implement your code

33 Requirements The requirements are defined in the lab write-up that is handed out –If they are unclear, you should get clarification from the customer (me!) From the requirements, begin thinking about the classes, responsibilities, and relationships –It may be helpful to do this BEFORE you look at the code that was provided

34 CRC Cards Discover classes –Most, if not all, classes are already determined Discover responsibilities –Relate the method names to the verbs in the requirements Describe relationships –Consider whether there are other relationships between the classes besides those already established

35 Javadoc Examine the javadoc that is included with the lab –Consider how the methods relate to the responsibilities on the CRC cards –Consider whether there are other methods that should be included

36 Implementation Implement the code using test-driven development

37 Summary The life cycle of software encompasses all activities from initial analysis until obsolescence The waterfall model describes a sequential process of analysis, design, implementation, testing, and deployment The spiral method describes an iterative process in which design and implementation are repeated Extreme Programming is a methodology that strives for simplification and focuses on best practices In object-oriented design, you discover classes, determine the responsibilities of the classes, and describe the relationships between classes A CRC card describes a class, its responsibilities, and its collaborating classes

38 Summary (cont’d) Inheritance (the is-a relationship) is sometimes inappropriately used when the has-a relationship would be more appropriate Aggregation (the has-a relationship) denotes that objects of one class contain references to objects of another class Dependency is another name for the uses relationship UML uses different notations for inheritance, interface implementation, aggregation, and dependency Use javadoc comments to document the behavior of classes

39 Questions?

40 Efficiency of Algorithms Difficult to get a precise measure of the performance of an algorithm or program Can characterize an algorithm by how the execution time increases as a function of the size of the input (asymptotic performance) –Big-O notation

41 Common Growth Rates

42 Growth Rate Functions

43 Growth Rate Table n O(1)11111 O(log n) O(n) O(n log n) x10 6 9x O(n 2 ) O(n 3 ) O(2 n ) x O(n!) 9x10 157

44 What is the Big-O of this algorithm for (int i=0; i

45 What is the Big-O of this algorithm for (int i=0; i

46 What is the Big-O of this algorithm for (int i=0; i=i; j--) System.out.println(i + “ “ + j);

47 What is the Big-O of this algorithm for (int i=1; i

48 Questions?


Download ppt "COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms."

Similar presentations


Ads by Google