DOC PREVIEW
Duke CPS 108 - Spring 2004

This preview shows page 1 out of 4 pages.

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

Unformatted text preview:

Software Design1.1CPS 108, Spring 2004z Software Design and Implementation¾ Object oriented programming and design• Language independent concepts including design patterns, e.g., Model-View-Controller, iterator, factory, bridge, …• Design independent concepts, e.g., coupling, cohesion, testing, refactoring, profiling, …zWhat’s in the course?¾ C++ and Java, team projects, mastery exams• team projects can be more and less than the sum of their parts¾high-level abstractions, low-level details• patterns, heuristics, and idiomsSoftware Design1.2Application Programming Interface, APIz Standard C++ headers, STL headers¾ Curses¾ wxWindowsz Java API¾ java.util, javax.swing, java.net, javax.crypto, …¾ Eclipse SWTz Google APIz Gracenote APISoftware Design1.3Program Design and Implementationz Language independent principles of design and programming¾ design heuristics• coupling, cohesion, small functions, small interfaces ...¾design patterns• factories, adapter, MVC, decorator, iterator, …zLanguage specific:¾ Idioms• smart pointers, vectors/arrays, overloaded operators ...¾idiosyncracies, idiocies• must define virtual destructor, stream zoo in Java, ...Software Design1.4Administriviaz check website and bulletin board regularly¾ http://www.cs.duke.edu/courses/cps108/current/¾ See links to bulletin board and other stuffz Grading (see web pages)¾ group projects: small, medium, large¾ mastery programs (solo or semi-solo endeavors)¾ readings and summaries¾ testsz Evaluating team projects, role of TA, UTA, consultants¾ face-to-face evaluation, early feedbackz Compiling, tools, environments, Linux, Windows, Mac¾ g++ 3.3, Java 2 aka 1.4, JRE, …Software Design1.5wordlines.cpp, understanding codetypedef map<string, set<int> > linemap;while (getline(input,line)) {linecount++;istringstream iline(line);while (iline >> w) {linemap::iterator it = info.find(w);if (it == info.end()) {set<int> si;si.insert(linecount);info.insert(make_pair(w,si));}else {it->second.insert(linecount);}}}Software Design1.6Questions about wordlines.cppz Conceptually, what's a map and what's a set?z In terms of implementation how do they work?z What's an iterator (abstractly and concretely)z What are streams? ifstream, cin/cout, istring/ostring, …z What's a templated class?z Other questions?Software Design1.7Classes: Review/Overviewz A class encapsulates state and behavior¾ Behavior first when designing a class¾ Information hiding: who knows state/behavior?z State is private/protected; some behavior is public¾ Private/protected helper functions¾ A class is called an object factory, creates lots of instancesz Classes communicate and collaborate¾ Parameters: send and receive¾ Containment: has a reference to¾ Inheritance: is-aSoftware Design1.8C++ (and Java) class constructionz C++ uses .h and .cpp, Java uses .java¾ Documentation different (javadoc vs. ???)z Default ctor, copy constructor, destructor, assignment operator¾ tvector, string, Date¾ Copy constructor needed to avoid shallow copy¾ In C++ destructors needed to free resources/self, Java?¾ Clone makes copy in Java (rare), share is default z Private, protected, public, (package)¾ Private default in C++, package default in Java¾ Per method declaration in Java, class sections in C++Software Design1.9Design CriteriaGood design comes from experience, experience comes from bad designFred Brooks (or Henry Petroski)z Design with goals:¾ ease of use¾ portability¾ ease of re-use¾ efficiency¾ first to market¾ ?????Software Design1.10How to codez Coding/Implementation goals:¾ Make it run¾ Make it right¾ Make it fast¾ Make it smallz spiral design (or RAD or !waterfall or ...)¾ what’s the design methodology?specificationdesignimplementationSoftware Design1.11XP and Refactoring(See books by Kent Beck (XP) and Martin Fowler (refactoring))z eXtreme Programming (XP) is an agile design process¾ Communication: unit tests, pair programming, estimation¾ Simplicity: what is the simplest approach that works?¾ Feedback: system and clients; programs and stories¾ Courage: throw code away, dare to be great/differentz Refactoring¾ Change internal structure without changing observable behavior¾ Don’t worry (too much) about upfront design¾ Simplicity over flexibility (see XP)Software Design1.12Modules, design, coding, refactor, XPz Make it run, make it right, make it fast, make it smallz Do the simplest thing that can possibly work (XP)¾ Design so that refactoring is possible¾ Don’t lose sight of where you’re going, keep change in mind, but not as the driving force [it will evolve]z Refactor: functionality doesn’t change, code does¾ Should mean that new tests aren’t written, just re-run¾ Depends on modularity of code, testing in piecesz What’s a module in C++¾ Could be a class, a file, a directory, a library, a namespace¾ We should, at least, use classes, files, directoriesSoftware Design1.13Design Heuristics: class/program/function(see text by Arthur Riel)z Coupling¾ classes/modules are independent of each other¾ goal: minimal, loose coupling¾ do classes collaborate and/or communicate?z Cohesion¾ classes/modules capture one abstraction/model¾ keep things as simple as possible, but no simpler¾ goal: strong cohesion (avoid kitchen sink)z The open/closed principle¾ classes/programs: open to extensibility, closed to modificationSoftware Design1.14C++ idioms/general conceptsz Genericity¾ Templates, STL, containers, algorithmsz Copy/Assignment/Memory¾ Deep copy model, memory management “required”z Low-level structures¾ C-style arrays and strings compared to STL, Tapestryz const¾ Good for clients, bad for designers/coders?z From C to C++ to Java¾ function pointers, function objects, inheritanceSoftware Design1.15Standard Librariesz In C++ there is the Standard Library, formerly known as the Standard Template Library or STL¾ Emphasizes generic programming (using templates)¾ Write a sorting routine, the implementation depends on• Elements being comparable• Elements being assignableWe should be able to write a routine not specific to int, string or any other type, but to a generic type that supports being comparable/assignablez In C++ a templated function/class is a code-factory, generates code specific to a type at compile time¾ Arguably hard to use and unsafeSoftware Design1.16Eric Raymondz Open source evangelist¾ The Cathedral and the Bazaarhttp://ot.op.org/cathedral-bazaar.html¾ How to


View Full Document

Duke CPS 108 - Spring 2004

Download Spring 2004
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 Spring 2004 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 Spring 2004 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?