Software Engineering I
Software Engineering I CSI 3471
Popular in Course
Popular in ComputerScienence
This 23 page Class Notes was uploaded by Melvin Bednar on Saturday October 3, 2015. The Class Notes belongs to CSI 3471 at Baylor University taught by Paul Grabow in Fall. Since its upload, it has received 44 views. For similar materials see /class/217932/csi-3471-baylor-university in ComputerScienence at Baylor University.
Reviews for Software Engineering I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/03/15
Outline 39 Not everything is of equal importance in this chapter 39Tlne date enampleisnot suclagreat enample skin 0 Important sections rngotalondeningsspecialtopic r320penaton overloading special topic 393 importanceolencapsdlationeverything r3 Analyzingtlre nalitpolanin ace everything 39 3 3 l 5 q tenl 6Programmingbpcontractleverptlning r dUnittestingwelranealneadpdonetlni inlalr zlplzoop DrPanlCGraloow Some Design Principles rrlninstanceolaclassslouldbe r Tamperpnool39 rWelllrelnaved r Instances of a particular class should be r Ordered r Unique r Cohesive r Complete 39llVOitl coupling between classes 292009 Principles amp Prog Language 0 To achieve good designs A programming language is necessary but not sufficient Design principles should guide iiesigns Use ofa programming language notvlce yersa 39 A good programming language cannot guarantee a good design 0 Clever programmingquot often at odds with good design zgzmg DxPauJ Grahow quotTamperproof classes 0 Distinguish between accessors and mutators 341 use mutators sparingly in An accessor function Only gets a value 0 Does not create a side effect 0 User of the object should not 0 Not have direct access to data within the object 109 Be given a address ofdata from within the object 112 39 Use private and private nal to protect object data 113 DxPauJ Grahow Wellbehaved 0 An object should only Do what it is supposed to do and nothing more 0 Each method in the object should behave The same way each time that it is called 39 A method39s behavior should not be in uenced by The values of its parameters DxPauJ Grahow Dr PaulCGrabow 2 292009 Law of Demeter 0 Amethod should onlyuses 0 Instance fields of its class 0 Parame o Objects that it constructs using new 0 Such a method does not operate on 0 Global ob39e t c s o Objects within other objects 0 Implies that a class shoul not 0 Return a reference to an object that is part of its internal implementation n7 DxPauJ crime Ordered and Unique 0 Assume several instances ofa class o Each instance should be unique Ifnot One object could be mistake n n foranother even though their no skey eldsare not identical 0 The collection should be ordered Ifnot e Someone will eventually de ne their own ordering pn based on 39m39it39ive operations increasing work and confusion DxPauJ crime Class Cohesion 0 Good cohes39o The extent to which lass demonstrates a focus All methodssupportasingle purpose 0 Poor cohesion Methods are not necessaril y related Lack of focus with respect to Data Functions o Not all or nothi quot There are degrees of cohesion DxPauJ crime Dr Paul C Grabow Adapter Pattern package adapterprj import javautil public interface SetInterface public boolean insert Object anObject public boolean remove Object anObject public boolean islnObject anObject public boolean isEmpty public void clear public int count public String toString public Iterator iterator package adapterprj import javautil public class PersonSet implements SetInterface TreeSet theSet k public PersonSet theSet new TreeSet param anObject Object return boolean public boolean insertObject anObject Add element only if element not null if anObject instanceof Person Person aPerson Person anObject if laPersonisNull return theSetaddaPerson else return false else return false 1 of 6 kk k param anObject Object return boolean public boolean removeObject anObject Add element only if element not null if anObject instanceof Person Person aPerson Person anObject Remove a particular element from set return theSetremoveaPerson else return false k k param anObject Object return boolean public boolean islnObject anObject Add element only if element not null if anObject instanceof Person Person aPerson Person anObject return theSetcontainsaPerson else return false return boolean k public boolean isEmpty return theSetisEmpty kk k public void clear Remove all elements of set theSetclear 2 of 6 return int k public int count return theSetsize return String k public String toString return theSettoString return Iterator public Iterator iterator return theSetiterator package adapterprj public class Person implements Comparable javaioSerializab1e Primary key attributes protected String mifirstname protected String milastname Constructors Person default constructor sets both first and last names to NULL7STRING public Person mifirstname CommonNULL7STRlNG milastname CommonNULL7STRlNG Person constructor param aFirstname param aLastname k public PersonString aFirstname String aLastname String tempFirst CommonnormalizeaFirstname String tempLast CommonnormalizeaLastname if CommonisValidNametempFirst ampamp CommonisValidNametempLast anirstname 7 tempFirst nLlastname tempLast else m firstname 7 7 CommonNULL7STRlNG nLlastname CommonNULL7STRlNG Extractors kk Get the first name return a String representing first name public String getFirstname return mifirstname Get the last name return a String representing last name public String getLastname return milastname k k ls firstname and lastname an empty string public boolean isNull boolean result result mifirstname ommonNULL7STRlNG ampamp milastname CommonNULL7STRlNG return result Relational operators kk Determine equality based on both first and last names param aPerson return boolean public boolean isEqualPerson aPerson return compareToaPerson 0L kk If last names are equal the first names param aPerson return boolean then base comparison solely on 4 of 6 public boolean isLessPerson aPerson return compareToaPerson lt 0 k If last names are equal then base comparison solely on the first names param aPerson return boolean public boolean isGreaterPerson aPerson return compareToaPerson gt 0 return firstname lastname k public String toString return mifirstname quot quot milastname k Same as isEqual param aPerson return boolean public boolean equalsPerson aPerson return compareToaPerson 0 x ltPgtless than negative integer equal zero greater than positive integerltPgt param anObject return 39nt x public int compareToObject anObject Person aPerson Person anObject int lastCmp milastnamecompareTolgnoreCaseaPersonm4lastnameL if lastCm O return mifirstnamecompareTolgnoreCaseaPersonm7firstname else return lastCmp package adapterprj public class Common Operations and data that are common to all of the other classes 5 of 6 package adapterprj public class myApp public myApp public static void mainString mYApp mYAppl new mYApp0 argsgt 60f6 1182008 S Java Types Part 1 Dr Paul C Grabow Baylor University SE Types Two Categories Primitive Reference boolean array char 15 blBQ bytes class byte 8km interface short 15 bits int 32 bits long 54 blB oat 32 bits double 54 blB 1m2ma Dr Paul c Grabow 2 Highlights Java boolean not an integral type boolean myFlag 0 Error I C bool is an integral type bool yourFlag 0 OK 1m2ma Dr Paul c Grabow 3 Dr Paul C Grabow 1 1182008 Highlights cont Numeric literal eg 50370 Assigned automaticall to type int ifvalue ts in 32 bits type long if value needs more than 32 bits Append the letter L or I to force the literal to a ong eg 100L 1m2ma Dr Paul c crabuw 4 Highlights cont Java rt slze long dlstance snort la long are complete type narnes C snortlntyourslze long lntyourDlstance Signedtypes I Java l lOl le C slgnedlntorunslgnedlnt Be careful wnen conyerung trorn C 1m2ma Dr Paul c crabuw 5 Highlights cont C char could be used to store any byte Java char cannot be used to store any byte used solely to store a cnaracter lnternal representauon lSUl llCOde Mobyte represertanon slrnllar to deaLt ln C no need to dlsungulsn between wlde or narrow cnaracters 1m2ma Dr Paul c crabuw o Dr Paul C Grabow 1182008 5H Highlights cont Floating point storage conforms to IEEE 754 standard provides distinct values for positive and negative Zeros positive and negative infinities and N i e nota num er a NaN can represent the result ofa oating point operation that would otherwise cause an error 1152ma Dr Paul c Giatuw 7 SE Highlights cont Size of primitive types Java same for all platforms C not same for all platforms Variable as a Pointer type Java no C yes and used extensively More about this later 1152ma Dr Paul c Giatuw a H gh ghts cont Casting primitive types looks like standard c notauori automauc conversons byte to short snortm ll it unlike c no smnc cast or dynamic cast Implicit casts in function arguments c someumes case wnedner or not me range of values ll i me desnriauori is greater or smaller man me range ll i line source Java does not do in 7 so be careful 1152ma Dr Paul c Giatuw 9 Dr Paul C Grabow 3 1182008 EH Highlights cont long BigNum 9876543210L int aNum bNum aNum int BigNum OK in java bNum int BigNum OKin C not OK in Java 1m2ma Dr Paul c Giabuw m Highlights cont Wrapper classes Primitive type Boolean boolean Byte byte Character char Double double Float oat Integer Int Long long Short short llEZEEIE DY Paul C Giabuw 11 g Highlights cont Wrapper classes Derive from Number class All are declared final eg Integer class contains IntegerMAXVALUE and IntegerMINVALUE eg Character class contains CharacterisDigit and CharacterisSpace 1m2ma Dr Paul c Giabuw 12 Dr Paul C Grabow 4 1182008 EH Highlights cont Java does not contain struct union Java does contain I enum llEZEEIE DY Panic Gvabuw 13 Dr Paul C Grabow 5 Introduction to UML 9112001 slntroduction to UML Dr Paul Grabow Baylor University reference UM in aNuls eI by Alhir O39Reilly 1998 What is UML The uni ed Modeling Language Not simply a notation but a complete language to model 5 stems s ntagtlt and semantics Used for specifying visualizing constructing and documenting systems expressing system development artifacts 9112um Dr Paul Grabow 2 lIow did UML originate Collaborative effort during the 1990s by Grady Booch James Rumbaugh Ivar Jacobson Combination of ideas from the above Three Amigos 9112um Dr Paul Grabow 3 Dr Paul Grabow 1 Introduction to UML 9112001 What does UML unify Booch s objectoriented designconstruction approach Rumbaugh s Object Modeling Technique OMT for describing data dependencies Jacobson s methods for requirements analysis Other good engineering practices 9112um Dr Paul Grabow 4 Goals of UML Desired characteristics readytouse expressive simple and extensible implementation indepen ent process independent scalable widely applicable Based on formal set of core concepts Allow specialized concepts notation and constraints beyond the core 9112um Dr Paul Grabow 5 More Characteristics of UML Focuses on standard modeling language and not a standard process Uses objectoriented community s consensus on core modeling concepts Allows model interchange among tools 9112um Dr Paul Grabow 5 Dr Paul Grabow Introduction to UML 9112001 Q What UML is Not Not a visual programming language Not a tool or repository specification Not a process or a method Not simply a notation 9112um Dr Paul Grabow 7 g The Definition of UML Expressed in four documents UML semantics UML notation guide UML extension for objectory process for software engineering UML extension for business modeling 9112um Dr Paul Grabow a Evolution of UML From mid19805 through mid19905 various modeling languags some objectoriented 1St generation modeling languages increase from 10 to more than 50 between 1989 and 1994 method warsquot due to competing methods lack of consensus discouraged vendor support 2rid generation mid19905 iterations on the 1St generation methods eg OMTZ 9112um Dr Paul Grabow 9 Dr Paul Grabow Introduction to UML 9112001 Evolution of UML cont 1994 Rumbaugh joins Booch at Rational Software Corporation 1995 Booch amp Rumbaugh relmse version 08 ofUML 1995 Jacobson joins Rational 1997 OMG Object Management Group standardizes UML 9112um Dr Paul Grabow 1n Industrialization of UML Occurring now late 1990s Industry organizationsvendors embrace UML Products and services for UML emerge Books and training appear 9112um Dr Paul Grabow 11 What does UML facilitate Specifying visualizing understanding and documenting problems Capturing communicating and leveraging knowledge during problem solving Specifying visualizing constructing and documenting solutions 9112um Dr Paul Grabow 12 Dr Paul Grabow 4 Introduction to UML 9112001 Problem Solving Figure 22 9112um Dr Paul Grabow 13 g Model Views Structural View lrrpierneritauori View i 9112um Dr Paul Grabow 14 Model Views I User view involves a problem and solution perspective problem owners and their requiremenE for a tion so u I Structural view smtic aspects ofa problem and solu on I Implemenmtion view structural and behavioral aspecE of the solu on s realization I Behavioral view dynamic aspects ofa problem and solution I Environment view structural and behavioral aspecE of the domain in which the Solution is realized 9112um Dr Paul Grabow 15 Dr Paul Grabow Introduction to UML 9112001 Analysis and Design What does analysis investigate the problem What is the purpose of design to describe a solution that adequately addresses the problem 9112um Dr Paul Grabow 15 g ObjectOriented Paradigm What is objectoriented analysis finding and describing objects and conce ts in the I roblem domain What is objectoriented design defining objects that when combined constitute an adequate solution to the problem 9112um Dr Paul Grabow 17 An AnalysisDesign Process Step 1 De ne Use Cases Step 2 De ne a Domain Model Step 3 De ne Collaboration Diagram Step 4 De ne Class Diagram 9112um Dr Paul Grabow m Dr Paul Grabow 6 Introduction to UML 9112001 Example Problem Your car is nearly out of gas It contains only enough gas to get you to the nearest gas station 9112um Dr Paul Grabow 19 g Related Use Case Use case Fill car with gas Actors car owner Car owner drives car to gas station where heshe fills the tank with gas and pays the attendant Description 9112um Dr Paul Grabow 2n Related Domain Model 9112um Dr Paul Grabow 21 Dr Paul Grabow Introduction to UML 9112001 Related Collaboration Diagram Operation ll car with gas Mobil Smtion 9112um Dr Paul Grabow 22 g Related Sequence Diagram 9112um Dr Paul Grabow 23 g Related Class Diagram 9112um Dr Paul Grabow 24 Dr Paul Grabow 8 ObjectOriented Design amp Patterns Chapter 6 Questions U39I Revised 10312008 Inheritance and Multiple Inheritance a What is multiple inheritance b What potential problems does multiple inheritance create pp 246f c When should I note use inheritance pp 254f The Substitution Principle a State the substitution principle and given an example of its use b What problem does this principle attempt to avoid Preconditions and Post conditions with Inheritance a What must I avoid when defining a precondition for a subclass b What must I avoid when defining a post condition for a subclass Graphics Programming with Inheritance a What are the two listener interfaces for a mouse event b Why are there two listener interfaces for a mouse event c What is the purpose of the two mouse adapter classes d Understand the CarComponentMover example You can find the code at ProfDataGrabowcsi347lWorkspacecar Abstract Classes a Can you construct an object based on an abstract class b What is the benefit of using the SelectableShape abstract class in the scene example c Explain the scene example using the class diagram on p 230 d Is it legal to tag any class as abstract even if all of its methods are already defined Should you do this e Can a class extend more than one abstract class Can a class implement more than one interface f Compare class CarComponent pp 226f and class SceneComponent pp 232f with respect to their attributes Why is there a difference g What is the default layout used to create the buttons JPanel on p 234 h Execute the scene3 example its location is the same as the car example mentioned above What code executes when you hit the Remove button and there is nothing to remove 6 The Template Method Pattern 7 8 a What problem does this pattern address b Describe the nature of this solution using the class diagram on p 237 c How does scene2 use the template method pattern d Why and how is CarShape in the scene2 example different from CarShape in the scenel example Protected Interfaces a What is a protected interface b How does scene3 implement a protected interface Later a The Hierarchy of Swing Components b The Hierarchy of Standard Geometric Shapes c he Hierarchy of Exception Classes