ebook img

Software Design Using Java 2 PDF

320 Pages·2002·1.869 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Software Design Using Java 2

Software Design Using Java 2 Kevin Lano, José Luiz Fiadeiro and Luís Andrade ©KevinLano,JoséLuizFiadeiroandLuísAndrade2002 Allrightsreserved.Noreproduction,copyortransmissionof thispublicationmaybemadewithoutwrittenpermission. Noparagraphofthispublicationmaybereproduced,copiedor transmittedsavewithwrittenpermissionorinaccordancewith theprovisionsoftheCopyright,DesignsandPatentsAct1988, orunderthetermsofanylicencepermittinglimitedcopying issuedbytheCopyrightLicensingAgency,90TottenhamCourt Road,LondonW1T4LP. Anypersonwhodoesanyunauthorisedactinrelationtothis publicationmaybeliabletocriminalprosecutionandcivil claimsfordamages. Theauthorshaveassertedtheirrighttobeidentified astheauthorsofthisworkinaccordancewiththe Copyright,DesignsandPatentsAct1988. Firstpublished2002by PALGRAVEMACMILLAN Houndmills,Basingstoke,HampshireRG216XSand 175FifthAvenue,NewYork,N.Y.10010 Companiesandrepresentativesthroughouttheworld PALGRAVEMACMILLANistheglobalacademicimprintofthePalgrave MacmillandivisionofSt.Martin’sPress,LLCandofPalgraveMacmillanLtd. Macmillan®isaregisteredtrademarkintheUnitedStates,UnitedKingdom andothercountries.PalgraveisaregisteredtrademarkintheEuropean Unionandothercountries. ISBN 978-1-4039-0230-6 ISBN 978-1-4039-1466-8 (eBook) DOI 10.1007/978-1-4039-1466-8 Thisbookisprintedonpapersuitableforrecyclingandmadefromfully managedandsustainedforestsources. AcataloguerecordforthisbookisavailablefromtheBritishLibrary. 10 9 8 7 6 5 4 3 2 1 11 10 09 08 07 06 05 04 03 02 Contents Preface vii 1 Software Design 1 1.1 What is Software Design? 1 1.2 What is a Good Design? 9 1.3 Notations for Software Design 12 1.4 History and Background 22 2 Design Techniques 25 2.1 Design Steps 25 2.2 Architectural Design 26 2.3 Subsystem Design 28 2.4 Module Design 30 2.5 Detailed Design 32 2.6 Generic Design Techniques 34 2.7 Software Development Projects 39 3 Software Architectures 50 3.1 Architectures 50 3.2 User Interface Design 53 3.3 Design of Databases using JDBC 75 4 Design Patterns 87 4.1 The History of Design Patterns 87 4.2 The State Pattern 90 4.3 The Template Method Pattern 93 4.4 The Visitor Pattern 96 4.5 The Observer Pattern 99 4.6 The Iterator Pattern 101 4.7 The Mediator Pattern 104 4.8 The Proxy Pattern 109 iii iv Contents 4.9 Creational Patterns 112 4.10 Structural Patterns 117 4.11 Behavioural Patterns 122 4.12 Selection of Design Patterns 125 5 Coordination Contracts 130 5.1 Beyond Object-oriented Design 130 5.2 Why Object-Orientation is not Evolutionary 132 5.3 Coordination Contracts 136 5.4 Defining Patterns using Contracts 140 5.5 Invariant-driven Development 149 6 Business Information Systems 153 6.1 Case Study: Coordination in Stock Trading 153 6.2 Creating and Deleting Contract Instances 158 7 Reactive System Design 163 7.1 Reactive Systems 163 7.2 Structuring of Reactive Systems 169 7.3 Fault Detection 174 7.4 Scheduling 175 7.5 Coordination Contracts in Reactive Control Systems 179 7.6 RSDS 180 8 Distributed and Internet Applications 183 8.1 Architectures for Internet Applications 183 8.2 JavaScript 188 8.3 HTTP GET and POST Requests 195 8.4 JavaServer Pages (JSP) 196 8.5 Java Servlets 204 8.6 Three Tier Applications 211 8.7 Design Patterns for Internet Applications 217 A Java in Five Easy Pieces 221 A.1 Basic Java Programs and Data Types 221 A.2 Defining Classes 232 A.3 Conditional and Loop Statements 243 A.4 Inheritance and Subclasses 252 A.5 Data Structures 263 B Design Case Study 269 B.1 Architectural and Subsystem Design 269 B.2 GUI Design 270 B.3 The Strategy Subsystem 275 B.4 Design Refactorings 287 B.5 Persistency Subsystem 289 Contents v B.6 Other Term Projects 295 Bibliography 301 Index 304 This page intentionally left blank Preface The use of Java as the first language in computer science courses is by now well established world-wide and supported by textbooks. Such courses typi- callycoverthebasicaspectsofobject-oriented programmingwithemphasison thecontrol structuresmadeavailable in Java. This book contains an introduc- tion to Java suitable for a first course in programming, and provides support materials including a computer-aided learning tool. However, software engineering as a discipline requires another level of ma- turity to be attained: that of software design and “programming in the large”, whichcoverstheuseoflanguageslikeJavaforthedevelopmentofcompleteand high-quality applications. This level is concerned with the development ofsys- tems as opposed to programs, in the sense that the complexity that is involved in their development is not of an algorithmic nature, but results from the need to construct and evolve applications as systems of interconnected components. Thisbookcoversalltheessentialtechniquesneededtodesignsoftwaresystems using object technology: design patterns, architectural, subsystem and module design,userinterfacedesign,web-basedsystemdesignanddatabasedesign. The rapidly growing array of Java technology products across all areas of software development means that it is the natural language of choice for teaching these issues, so we use Java Swing for user interface construction, JavaScript, JSP and Servlets for web-based system design, and JDBC for database interfacing. Wealsointroducetheindustry-standardUMLnotationforanalysisanddesign. Unlike traditional engineering design, software design must produce sys- tems which can be extended and modified relatively easily. There is an in- creasingneedinindustryforsoftwaretosupportevolutionofrequirements,the rapid addition of services, and a wide variety of customer needs. The book addresses this issue as a central design goal, and introduces an extension of object-oriented concepts, called coordination contracts, which supports flexi- bility by separating the program logic, or coordination of components, from the software components that this logic applies to. This approach has been developed and applied by the authors in a variety of application areas, from banking to telecommunications and control systems. On the CD we provide tools for implementing contracts in Java. vii viii Preface All material has been class tested in our own courses, and we include com- pletecodeaswellascomprehensiveinstructionsonhowtoconstructtheexam- ple systems presented. The book can be used throughout a computer science degreecourse,andisparticularlyaimedatsupportingstudentsembarkingona grouporindividualproject–whentheimportanceofdesignissuesfirstbecomes a serious matter for many future software developers. Guidelines for Teaching Chapter 1 introduces program design and the UML notation. Chapter 2 de- scribesgeneric design steps and techniques, and guidelines for software project management. Chapter 3 covers GUI and database design. Chapter 4 describes 14 common design patterns. Chapters 5 and 6 cover the concept of coordi- nation contracts and their application in design. Chapter 7 deals with design issues for reactive systems, and Chapter 8 gives programming and design tech- niques for web-based applications. Appendix A gives a rapid introduction to Java, and Appendix B gives a case study of software design. We use the material in Appendix A in an introductory course in program- ming using Java, and Chapters 1 to 4, plus Chapter 8 and Appendix B, for a second year program design course. Chapters 5, 6 and 7 can be used in advanced design courses. Acknowledgements The introductory Java material presented in Appendix A was originally de- veloped by Malcolm Bird at King’s College London. Kelly Androutsopolous, DavidClark,ArturoSanchezandPaulineKancontributedtothedevelopment ofRSDS.ThesupportofATXSoftware,King’sCollegeLondonandProf. Tom Maibaum in providing the resources for developing this book is gratefully ac- knowledged. Manyofourstudentshavealsocontributedtothedevelopmentof the material in the book, in particular Gareth Davis (Chapter 8) and Depika Mistry (restaurant system case study). Jo˜aoGouveia,GeorgiosKoutsoukos,Anto´niaLopesandMichelWermelinger contributed to the development of the coordination contracts concept and the CDE tool. Chapter 1 Software Design This chapter describes the role of design in the software development process, and gives some desirable properties of software designs. It introduces three examples: a restaurant management system, an on-line football game, and a bank account management system, and describes what the design process consists of for these systems. 1.1 What is Software Design? No-one would attempt to build an aeroplane or a bridge without careful plan- ning of how the overall structure is going to be organised, what components and materials are needed and how they will fit together. For novel designs, such as the flat suspension bridge known as the “Millennium Bridge” over the river Thames in London, even more care is needed to ensure that the system when built will actually behave as expected1. For software the same principle applies: for small programs, under 100 lines, with one or two classes, we can often get away with hacking together some code at the terminal, and end up with something which, most of the time, works as intended. But this is far from the reality of industrial software production, where new systems have to be planned with care to ensure that theyworkcorrectlywithexistingsystems,thattheyarereliable,andthatthey canbeextendedandmaintainedbypeopleotherthantheoriginalprogrammer. Software design is essential for any non-trivial program: unless care is taken to structure the code into sensible classes and methods, a program can quickly become very difficult to debug or extend. In this book we will use the following practical definition which sets the scope of what we will be covering: 1Duetoanerrorintheanalysisofthisfootbridge,whichignoredthefactthatpedestrians produce lateral forces as well as vertical forces, the bridge started swaying excessively and hadtobeclosedforoverayearwhileexpensivemodificationswerecarriedout. 1

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.