comp 121 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
COMP 121 PowerPoint Presentation
Download Presentation
COMP 121

Loading in 2 Seconds...

play fullscreen
1 / 48

COMP 121 - PowerPoint PPT Presentation


  • 150 Views
  • Uploaded on

COMP 121. Week 7: Object-Oriented Design and Efficiency of Algorithms. Objectives. Learn about the software life cycle Learn how to discover new classes and methods Understand the use of CRC cards for class discovery

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'COMP 121' - dory


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
comp 121

COMP 121

Week 7: Object-Oriented Design and Efficiency of Algorithms

objectives
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
objectives cont d
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
software life cycle
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
development process
Development Process
  • Analysis
  • Design
  • Implementation
  • Testing
  • Deployment
analysis phase
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?
design phase
Design Phase
  • Plans system implementation
  • Identifies Classes, Methods Needed
  • What is the output of the Design phase?
implementation phase
Implementation Phase
  • Write and compile the code
  • Implement classes and methods discovered in the design phase
  • Output?
testing phase
Testing Phase
  • Run tests to verify the program works correctly
  • Output: a report of the tests and their results, test coverage
deployment phase
Deployment Phase
  • Software installed and used for its intended purpose
the waterfall model1
The Waterfall Model
  • Sequential process of analysis, design, implementation, testing, and deployment
  • When rigidly applied, does not work well!
the spiral model
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
extreme programming
Extreme Programming
  • Strives for simplicity
  • Removes formal structure
  • Focuses on best practices
  • Realistic planning
  • Small releases
  • Metaphor
  • Simplicity
  • Testing
  • Re-factoring
extreme programming cont d
Extreme Programming (cont’d)
  • Focuses on best practices
    • Pair programming
    • Collective ownership
    • Continuous integration
    • 40-hour week
    • On-site customer
    • Coding standards
test driven development1
Test Driven Development
  • 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
discovering classes
Discovering Classes
  • Class represents set of objects with the same behavior
    • Entities with multiple occurrences in problemdescription 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?
crc cards
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
relationships between classes
Relationships Between Classes
  • Inheritance
  • Aggregation
  • Dependency
inheritance
Inheritance
  • Is-a relationship
  • Relationship between a more general class (superclass) anda 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
aggregation
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;}

aggregation cont d
Aggregation (cont’d)
  • Every car has a tire (in fact, it has multiple tires)

class Car extends Vehicle{ . . . private Tire[] tires;}

dependency
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
five part development process
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
discussion questions
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
requirements
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
crc cards1
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
javadoc
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
implementation
Implementation
  • Implement the code using test-driven development
summary
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
summary cont d
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
efficiency of algorithms
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
what is the big o of this algorithm
What is the Big-O of this algorithm

for (int i=0; i<n; i++)

for (int j=0; j<n; j++)

System.out.println(i + “ “ + j);

what is the big o of this algorithm1
What is the Big-O of this algorithm

for (int i=0; i<n; i++)

for (int j=0; j<2; j++)

System.out.println(i + “ “ + j);

what is the big o of this algorithm2
What is the Big-O of this algorithm

for (int i=0; i<n; i++)

for (int j=n-1; j>=i; j--)

System.out.println(i + “ “ + j);

what is the big o of this algorithm3
What is the Big-O of this algorithm

for (int i=1; i<n; i++)

for (int j=0; j<i; j++)

if (j%i == 0)

System.out.println(i + “ “ + j);