Card Set Information

2013-04-23 19:39:56
Software Development finmcoul

F27SB Software Development 2 Verena + Greg
Show Answers:

  1. Coupling
    • Dependency on another unit of the program
    • Aim for loose coupling
  2. Encapsulation
    • Hides information though private, protected and public variables
    • Reduces coupling
  3. Cohesion
    • Refers to the number and diversity of the task of each unit of the program
    • Aim for high cohesion
  4. Refactoring
    • When code is added it must be maintained
    • Test before and after to ensure nothing is broken
  5. JUnit Test
    • Automated test harness
    • Is done through the use of AssertTrue()
  6. JUnit Code
    • public void test() {
    • Game game = new Game();
    • Room start= game.getCurrentRoom(); Command command = new Command("go", "east");
    • game.goRoom( command ); assertTrue(!start.equals( game.getCurrentRoom()));
    • Command back = new Command("back", null);
    • game.goBack(back); assertTrue(start.equals( game.getCurrentRoom())); }
  7. Errors Types
    • Syntax Errors
    • Logic Errors
  8. Syntax Errors
    • Found when the program is compiled
    • Prevent the program from compiling
  9. Logical Errors
    • Found after program has ran
    • The manifestation may appear far from the source 
  10. Inheritance
    • Avoids code duplication/ increases ease of maintenance 
    • Improves cohesion
    • Reduces coupling 
    • Super classes define the common attributes( via fields)
    • Subclasses inherit superclass attributes 
  11. Subclass
    • Subclass inherits all methods and fields of the superclass
    • Sub class constructors must always contain a 'super' call
    • Super call must come first in the subclass constructor
  12. Subtyping
    • Classes define types
    • Subclasses define subtypes
  13. Subtyping Example
    • Subclass objects can be assigned to superclass variables eg downwards assignment
    • Vehical v = new Car(); // Ok
    • Car c = new Vehical(); // Error
  14. Polymorphic Variables
    Can hold variables of the declared type and the subtypes of the declared type
  15. Substitution
    Objects of subclasses can be used where objects of super-classes are required.
  16. Casting
    • You can cast up an inheritance tree 
    • You can cast a subtype to a supertype but not supertype to subtype
    • object is not changed when cast, it is only changed during that instance
    • Used to over typeloss
  17. Subtyping and Casting Directions
    • You may subtype down with no errors but loss of data
    • You may cast up with no errors
    • You can't cast down unless it has been upcast to that
  18. Upcasting Errors
    • Loss of data 
    • If you upcast an object then it will lose ass its properties, which were inhterited from below its current position
  19. Method Overriding
    • Superclass and subclass define methods with the same signature
    • Each has access to the fields in its class
    • Superclass satisfies static type check
    • Subclass method overrides the superclass method during run-time
  20. Method Lookup
    • The variable is accessed
    • Object stored in the variable is found
    • Class of object is found
    • Class is searched for method, if no method is found then search superclass
    • Repeat until match is found or hierarchy exhausted
  21. Super Method Calls
    • Overridden methods are hidden but can be accessed like so 
    • Super.method(...)
  22. Static & Dynamic Types
    • The declared type of a variable is its static  type 
    • The type of the object of a variable refers to its dynamic type
    • The compilers is to check for static error type violations
    • Fixed by overriding 
  23. Abstract Classes
    • Abstract classes can't be instantiated but can be subclassed
    • They serve as a super class for other classes
    • A subclass implement all abstract methods
    • Abstract methods make the class abstract
    • Abstract methods/classes reduce coupling and code duplication
    • Abstract classes may contain abstract methods and also implemented methods
    • Has dynamic lookup
  24. Multiple Inheritance
    • Having a class directly inherit from multiple ancestors 
    • Java does not allow multiple inheritance from classes but allows multiple inheritance from interfaces
  25. Interface
    • All methods are abstract
    • There are no constructors 
    • All methods are public 
    • All fields are public static and final
    • Implementing classes do not inherit code but are subtype to the inherited class
    • Method overriding is available with interfaces as well as classes
  26. instanceof Keyword
    The instanceof keyword can be used to test if an object is of a specific type or a subtype
  27. Interface vs. Abstract - Multiple Instances
    • A class may implement several interfaces
    • A class my only extend one abstract class
  28. Interface vs. Abstract - Default Implementation
    • Interface provides no code
    • A abstract class can provide implemented methods
  29. Interface vs. Abstract - Constants
    • Interfaces have static final constants(class fields only)
    • Abstracts have both instance and static constants
  30. Interface vs. Abstract - Third Party Convenience
    • An interface implementation may be added to any third party class
    • A third party class must be rewritten to only extend from the abstract class
  31. Review of Inheritence
    • Inheritance can provide shared implementation
    • How: concrete and abstract classes
    • Benefit: code reuse
    • Inheritance provides shared type information
    • How: Classes + interfaces
    • Benefit: polymorphism and specialisation
    • Improves code by loose coupling
  32. Review of Abstract Classes
    • Abstract methods allow static type checking without implementation 
    • Abstract classes function as incomplete superclasses
    • Abstract classes support polymorphism
    • Improves code by loose coupling
  33. Review of Interfaces
    • Interfaces provide specification without implementation as interfaces are fully abstract
    • Interfaces support polymorphism
    • Java interfaces support multiple inheritence
    • Improves code by loose coupling
  34. JFrames - Font
    • Font takes the format of(String
    • name,int style,int size)
    • Font f = New Font("Serif",Font.BOLD,18);
    • Label.setFont(f);
    • Sets  text in Label to font type serif in bold with size 18 text
  35. JFrames - Layout Managers
    • Border Layout
    • Grid Layout
    • Flow Layout
  36. JFrames - Border Layout
    • Container.add(BorderLayout.Position, Element);
    • Position can be NORTH,SOUTH,EAST,WEST or CENTER (note american spelling)
    • Element may be anything like a panel,label,button ect
  37. JFrames - Grid Layout
    • SetLayout(new GridLayout(int row,int column))
    • Creates layout of 3 rows and 2 columns
    • Adds left to right, top to bottom 
  38. JFrames - Flow Layout
    • SetLayout(FlowLayout());
    • makes componets as small as is compatible with contents
    • Adds left to right, top to bottom
  39. Polling
    • Generalises simple prompt/input/process/output approach
    • Program anticipates multiple input sources eg keyboard/mouse
    • It repeatedly checks up until all are ready then deal with the source and continues
    • Advantage: under user control
    • Disadvantage: need to decide when to poll and nothing else can be done while program is polling
  40. Interupt
    • An interrupt my be external/hard which is caused by something outside the CPU ie. an I/O device
    • An interrupt may be internal/soft which is caused by a subprogram eg interrupting a process to let another run
  41. Handling Interupts
    • When interrupt occurs, the CPU stops what it's doing, saves the info about the current state of the current program in dedicated memory and runs the code to handle the interrupt 
    • After the interrupt, information about the current program state is restored from the dedicated memory and the process resumes at the interrupted instruction
    • Java distinguishes an exception as a soft interrupt or program generated
    • Java distinguishes an event as a hard interrupt, an external activity
    • After an event the program continues with the current activity
    • Advantage: Doesn't waste time checking for external activity
    • Disadvantage: event breaks flow of processing
  42. JFrames - ActionListener
    • Class implements ActionListener
    • Public void actionPerformed(ActionEvent e)
    • {
    •    if(e.getsource == button
    •          action
    • }
  43. JFrame - JFrame Setup
    • Class extends JFrame implements Actionlistener
    • Imports java.util.*,javax.Swing.*,java.awt.*
    • JButton j = new JButton("original text");
    • j.setOpaque(true);
    • j.setFont("serif",Font.ITALIC,18);
    • j.setText("updated text");
    • j.addActionListener(this);
    • Container.add(j);