Specification and DesignUse formal specificationUse formal specificationsWhat you should know about formal methodsTests as specificationAdvantages of tests as specificationsDisadvantages of tests as specificationJUnitTesting Student and CourseNormal testSlide 11Tests as specificationsDesignLife-cycleA good designKeep It Simple (S)Keep it SimpleDavis Design PrinciplesSlide 19DavisMany things to designSlide 22What can go wrong?Too hard to add new featuresSeparate User InterfaceAutomated testsSummaryProject adviceNext time1Specification and DesignChapters 9,10,11CS427 14-2Use formal specificationTo develop models of parts of systemFinite state machines, abstract data typesTo develop model of one aspect of systemData-flow diagram, security, architectureTo learn how to think about problempre/post conditionsset,sequence,mappings (generic ADTs)CS427 14-3Use formal specificationsFor particular kinds of applicationscompilersgrammardenotational semanticssafety criticalCS427 14-4What you should know about formal methodsWhat is in the book – chapter 10Be familiar with the controversyDon’t need to learn PrologCS427 14-5Tests as specificationFormal specificationBalance after you add money to an account will be the balance beforehand plus the amount of money you addedTestCreate account with balance of $100Add $20 to accountAccount has balance of $120CS427 14-6Advantages of tests as specificationsConcrete, easy to understandDon’t need new languageEasy to see if program meets the specificationsMaking tests forces you to talk to customer and learn the problemMaking tests forces you to think about design of system (classes, methods, etc.)CS427 14-7Disadvantages of tests as specificationHard to test that something can’t happenCan’t withdraw more money than you have in the systemCan’t break into the systemCan’t cause a very long transaction that hangs the systemTends to be verboseCS427 14-8JUnitwww.junit.orgA test is a method in a subclass of TestCase.Calls methods (defined in TestCase) likeassertEqual(object1, object2)assertTrue(boolean)CS427 14-9Testing Student and Coursepublic void testStudentCreation() {Student s = new Student("Marvin Minsky");assertTrue(s.getName().equals("Marvin Minsky"));}orpublic void testStudentCreation() {Student s = new Student("Marvin Minsky");assertEqual(s.getName(), "Marvin Minsky");}CS427 14-10Normal testSet up “test fixture”Call method that is being testedAssert that result is correctCS427 14-11public void testAddingStudent(){ Course c; Student s; c = new Course("Tourism 101"); s = new Student("Donald Knuth"); c.addStudent(s); assertEquals(c.students().size(), 1); assertEquals(c.students().elementAt(0), s);CS427 14-12Tests as specificationsTests show how to use the systemTests need to be readableneed comments that describe their purposekeep short, delete duplicationCS427 14-13DesignVerbTo conceive or plan out in the mind.To make a drawing, pattern, or sketch of.CS427 14-14Life-cycleRequirements captureSpecificationDesignImplementationCS427 14-15A good designSatisfies requirementsEasy to implementEasy to understandEasy to changeEasy to check for correctnessIs beautifulCS427 14-16Keep It Simple (S)Everything should be as simple as possible, but no simpler. (Einstein)A design is finished not when there is nothing to add, but when there is nothing to take away. (Saint-Exupery)Measuring a program by the number of lines of code in it is like measuring an airplane by how much it weighs. (Gates)CS427 14-17Keep it SimpleAvoid duplicationEliminate unnecessary features/codeHide informationNo surprises (follow standards)CS427 14-18Davis Design PrinciplesDon’t reinvent the wheel.Search the web. Read the book. Talk to experts. Exhibit uniformity and integration.Make parts as similar as possibleCoding standardStandard namesCS427 14-19Davis Design PrinciplesMinimize the intellectual distance between the software and the problem as it exists in the real world.Use same names as your customersUse same models as your customersStructure the design to accommodate change.CS427 14-20DavisThe design should be structured to degrade gently, even when aberrant data, events, or operating conditions are encountered.The design should be assessed for quality as it is being created, not after the fact.The design should be reviewed to minimize conceptual errors.CS427 14-21Many things to designCompanySystem that uses programInterface to programInterface of module within programProcedureDatabaseCS427 14-22DesignProcess of eliminating “misfits”Find something wrong and fix itGood design requires being able to spot something that is wrongCS427 14-23What can go wrong?Too complex - can’t understandUsers can’t understandProgrammers can’t understandToo slowWrong featuresToo hard to add new featuresNot compatibleCS427 14-24Too hard to add new featuresUsually because problem is decomposed improperlyDesign decisions should be hiddenOnly one module should know about design decisionChanging that decision requires changing only one moduleCS427 14-25Separate User InterfaceSeparate user interface from program logicUI changes frequentlyIt is easier to change UI if it is separateUI experts can be non-programmersCan provide several UIs for one systemCS427 14-26Automated testsUI hard to testSeparate UI from program logic and write automated tests for program logic.UI first?No, design program logic first and write tests for it.Database first?No, design program logic first and write tests for it. Then design database and rewrite to use itCS427 14-27SummaryFuzzy boundaries between analysis and design design and implementationDesign is problem solvingIt helps to know a lot of solutionsCS427 14-28Project adviceYou are graded on how well you follow your process.You must know it.You must follow it.You must prove you follow it.Make a log of what you do every day.CS427 14-29Next timeRead chapter 13 and 14 of Hamlet and
View Full Document