DOC PREVIEW
CU-Boulder CSCI 5448 - Great Software

This preview shows page 1-2-14-15-30-31 out of 31 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Great Software Kenneth M Anderson University of Colorado Boulder CSCI 4448 5448 Lecture 5 09 08 2009 1 Lecture 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 1 2 The 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 3 Initial Application Guitar serialNumber String price double builder String model String type String backWood String topWood String getSerialNumber String getPrice double setPrice double getBuilder String getModel String getType String getBackWood String getTopWood String Inventory guitars List addGuitar String double String String String String String getGuitar String Guitar search Guitar Guitar Egads Alarm bells in the design center of your brain should be ringing like mad Why 4 Dumb Data Holder Guitar serialNumber String price double builder String model String type String backWood String topWood String getSerialNumber String getPrice double setPrice double getBuilder String getModel String getType String getBackWood String getTopWood String 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 5 The Manager Meet the Manager A manager is a single class that contains most of the application s services Inventory guitars List addGuitar String double String String String String String getGuitar String Guitar search Guitar Guitar For this simple application a 1 addGuitar too many params manager is okay but there are still problems Managers must be used with care its easy to centralize too many services within them 2 getGuitar why only one param 3 searchGuitar if I m looking for a guitar why am I passing one to the search method 6 Bad 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 unique 4 Ignore price since that s unique 5 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 30 31 This is really horrible code Why Lots of needless duplication Hard to Read Some Attributes of Guitar are being ignored 7 Plus 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 Also note typo on page 5 the code on that page doesn t return a guitar even if a match is FOUND 8 A 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 This will be a question that you will encounter in development all the time What do I do next 9 What 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 10 What is GREAT SOFTWARE continued Which programmer is correct All of the Above 11 Great 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 12 Great Software in Three Easy Steps Your FIRST OO A D Process Make sure your software does what the customer wants it to do Apply basic OO principles to add flexibility Strive for a maintainable reusable design 13 Step 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 problems 14 Improvements Ditch String Comparisons A string can have TONS of legal values But Guitar s type builder and wood attributes DON T Solution Use enumerated types to restrict the legal values This provides both type safety and value safety The compiler can now ensure that legal values are stored in our database and used in queries The code is now less fragile 15 Improvements II Fix search method to return more than one choice Rick specified this but the original coders failed to meet this requirement This is a small change involving creating a list to hold search results as we find them and modifying search to return this new list Demonstration Step 1 Complete The system now does what Rick wants 16 Step 2 Apply Principles Attention turns to the fact that a Guitar object is being passed to the search method when that s what we are looking for in the first place The problem Weak Encapsulation The Guitar class is being asked to serve as a Guitar object AND as a


View Full Document

CU-Boulder CSCI 5448 - Great Software

Documents in this Course
Django

Django

42 pages

ENRS

ENRS

30 pages

PhoneGap

PhoneGap

22 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?