Unformatted text preview:

Great SoftwareKenneth M. AndersonUniversity of Colorado, BoulderCSCI 4448/6448 — Lecture 5 — 09/11/20071Saturday, September 15, 2007Lecture Goals• Review material from Chapter 1 of the OO A&D textbook• What is Great Software?• How do you produce great software each time you participate in a development project• Discuss the Chapter 1 Example: Rick’s Guitars• Emphasize the OO concepts and techniques encountered in Chapter 12Saturday, September 15, 2007The Example• Rick’s Guitars• Purpose of Application?• Find Guitars for Rick’s Customers• Design of Initial Application?• Worse than Bad• What’s the Major Problem?• Application fails to find guitars that Rick knows exists!• Note: Customer Focus… we could have said “The problem is due to the use of a case-sensitive string comparison” but Rick wouldn’t care about that!3Saturday, September 15, 2007Initial ApplicationgetSerialNumber(): StringgetPrice(): doublesetPrice(double)getBuilder(): StringgetModel(): StringgetType(): StringgetBackWood(): StringgetTopWood(): StringserialNumber: Stringprice: doublebuilder: Stringmodel: Stringtype: StringbackWood: StringtopWood: StringGuitaraddGuitar(String, double, String, String, String, String, String)getGuitar(String): Guitarsearch(Guitar): Guitarguitars: ListInventoryEgads!Alarm bells in the design center of your brain should be ringing like mad!Why?4Saturday, September 15, 2007Dumb Data Holder• Meet the Dumb Data Holder• A “data holder” is a class that only stores information and is dumb since it provides ZERO services• get() and set() don’t count!• If this is all you are going to use an object for, you may as well go back to C and just use structs!getSerialNumber(): StringgetPrice(): doublesetPrice(double)getBuilder(): StringgetModel(): StringgetType(): StringgetBackWood(): StringgetTopWood(): StringserialNumber: Stringprice: doublebuilder: Stringmodel: Stringtype: StringbackWood: StringtopWood: StringGuitar5Saturday, September 15, 2007The Manager• Meet the “Manager”• A manager is a single class that contains most of the application’s services• For this simple application, a manager is okay, but… there are still problemsaddGuitar(String, double, String, String, String, String, String)getGuitar(String): Guitarsearch(Guitar): Guitarguitars: ListInventory1. addGuitar(): too many params2. getGuitar(): why only one param?3. searchGuitar(): if I’m looking for a guitar, why am I passing one to the search() method?Managers must be used with care: its easy to centralize too many services within them!6Saturday, September 15, 2007Bad Smell? public Guitar search(Guitar searchGuitar) {1 for (Iterator i = guitars.iterator(); i.hasNext(); ) {2 Guitar guitar = (Guitar)i.next();3 // Ignore serial number since that's unique4 // Ignore price since that's unique5 String builder = searchGuitar.getBuilder();6 if ((builder != null) && (!builder.equals("")) &&7 (!builder.equals(guitar.getBuilder())))8 continue;9 String model = searchGuitar.getModel();10 if ((model != null) && (!model.equals("")) &&11 (!model.equals(guitar.getModel())))12 continue;13 String type = searchGuitar.getType();14 if ((type != null) && (!searchGuitar.equals("")) &&15 (!type.equals(guitar.getType())))16 continue;17 String backWood = searchGuitar.getBackWood();18 if ((backWood != null) && (!backWood.equals("")) &&19 (!backWood.equals(guitar.getBackWood())))20 continue;21 String topWood = searchGuitar.getTopWood();22 if ((topWood != null) && (!topWood.equals("")) &&23 (!topWood.equals(guitar.getTopWood())))24 continue;25 return guitar;26 }27 return null;28 }29}3031This is really horrible code.Why?Lots of needless duplication Hard to ReadSome Attributes of Guitar are being ignored7Saturday, September 15, 2007Plus: It Doesn’t work!• The search relies on string comparisons and this is susceptible to problems between differences in what is stored and what is entered• In the case of the example• the database stored: “Fender”• the customer entered: “fender”• NO MATCH!8Saturday, September 15, 2007A Good Question• A team is assembled to fix the problem in the original tool and they ask a good question•How are we supposed to know where to start?• One designer wants to get rid of the ubiquitous use of strings in the app• One wants to improve the design• One sees that the current app doesn’t even do what the user wants• They just want to create great software, but how?9Saturday, September 15, 2007What is Great Software?•Customer-Friendly Programmer• Great software always does what the customer wants it to. So even if customers think of new ways to use the software, it doesn’t break or give them unexpected results•OO Programmer• Great software is code that is object-oriented. So there’s not a bunch of duplicate code, and each object pretty much controls its own behavior. It’s also easy to extend because your design is really solid and flexible.• Design-Guru Programmer• Great software is when you use tried-and-true design patterns and principles. You’ve kept your objects loosely coupled, and your code open for extension but closed for modification. That also helps make the code more reusable, so you don’t have to rework everything to use parts of your application over and over again.10Saturday, September 15, 2007What is GREAT SOFTWARE? continued• Which programmer is correct?All of the Above!11Saturday, September 15, 2007Great Software• Great software must satisfy the customer• The software must do what the customer wants it to do!• Great software is also• well-designed• well-coded• easy to maintain, reuse, and extend• So, how do we achieve this?12Saturday, September 15, 2007Great Software in Three Easy Steps• Your FIRST OO A&D Process!1. Make sure your software does what the customer wants it to do.2. Apply basic OO principles to add flexibility3. Strive for a maintainable, reusable design13Saturday, September 15, 2007Step 1: Customer First• The first step to fixing the program is to make sure it does what the customer wants• Do not worry about steps 2 and 3 at this point, simply figure out how to fix the problem in a straightforward manner• However, be smart about how you fix things• Don’t create problems to solve (other) problems14Saturday, September 15, 2007Improvements• Ditch String Comparisons• A string can have


View Full Document

CU-Boulder CSCI 6448 - Great Software

Documents in this Course
Struts

Struts

12 pages

Adapter

Adapter

23 pages

Prototype

Prototype

16 pages

Weka

Weka

15 pages

qooxdoo

qooxdoo

16 pages

Django

Django

12 pages

Overview

Overview

22 pages

XNA

XNA

5 pages

Load more
Download Great Software
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Great Software and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Great Software 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?