Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.

Similar presentations


Presentation on theme: "SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin."— Presentation transcript:

1 SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin

2 Agenda – Lecture 2b Review. OO basics Design
Mutability Exceptions Design Evolutionary design. TDD JUnit UML basics: class associations 11/29/2018 SOEN 343, © P.Chalin,

3 Java Basics – Hello World!
Illustrates: How to write the main method to be called when a program is invoked. Output (console). public class HelloWorld {   public static void main(String[] args) {      System.out.println("HelloWorld!");   } } 11/29/2018 SOEN 343, © P.Chalin,

4 Polymorphism “poly” – many “morphism” – forms
How does the meaning of this term apply to OO? Run-time type of a given expression can vary. Different types: our concern Subtype polymorphism. 11/29/2018 SOEN 343, © P.Chalin,

5 Number of Legs, Another Solution
Issues? class Animal { protected int numberOfLegs; public int getNumberOfLegs() { return numberOfLegs; } } class Duck extends Animal { public Duck() { numberOfLegs = 2; } Any design issues with this solution? Is it the simplest solution to our problem? Best solution? 11/29/2018 SOEN 343, © P.Chalin,

6 Exceptions, An Example: Throwing
public void m(String s) throws NullPointerException { if(s == null) { throw new NullPointerException(); } ... This slide illustrates: declaration throw 11/29/2018 SOEN 343, © P.Chalin,

7 Exceptions, An Example: Catching
public void m2(…) { String t = ...; try { m(t); } catch(NullPointerException e) { // t was null } finally { // code to exec no matter what } Catch and finally. 11/29/2018 SOEN 343, © P.Chalin,

8 Exception Class Hierarchy
Two types of exceptions Checked Unchecked Must be listed in method declaration. Must be caught – or run-time error is reported. No such restrictions. Throwable Error Exception RuntimeException SampleChecked 11/29/2018 SOEN 343, © P.Chalin,

9 Exceptions Both can throw exceptions. methods constructors
11/29/2018 SOEN 343, © P.Chalin,

10 What is a good design? Satisfies user needs.
Is a simple as possible. (Kent Beck) Runs all tests Reveals intention. No duplication. Fewest number of classes or methods 11/29/2018 SOEN 343, © P.Chalin,

11 Evolutionary Design What is the probability that a S/W design will need to be updated? Change is inevitable, evolutionary design recognizes this. As software is changed, generally it becomes more complex unless effort is made to keep it simple. 11/29/2018 SOEN 343, © P.Chalin,

12 Prerequisites to Successful Evolutionary Design?
Testing … lots of automated testing. Refactoring … keeping the design simple. Continuous integration Actually, testing is a prerequisite to refactoring. 11/29/2018 SOEN 343, © P.Chalin,

13 Test Driven Design Write tests first. TDD in its pure form
Why does it make sense to write tests first? TDD in its pure form Do not add any (product) code unless a test failing. 11/29/2018 SOEN 343, © P.Chalin,

14 Test Driven Design Enabling technologies *Unit, e.g. JUnit
11/29/2018 SOEN 343, © P.Chalin,

15 JUnit Basics: TestCase Class
Is a container for related test cases, not just one test case. Usage: subclass TestCase. E.g. public class MovieTest extends junit.framework.TestCase { … } 11/29/2018 SOEN 343, © P.Chalin,

16 TestCase Clase Usage: Test Methods
Write a method for each test. Method should be declared public void. Convention: method name starts with “test” public void testGetTitle(). By following the naming convention, individual tests will be picked up automatically (by reflection). 11/29/2018 SOEN 343, © P.Chalin,

17 A Test That Always Fails
public void testFailure() { fail(); } Yields junit.framework.AssertionFailedError at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.fail(Assert.java:53) at MovieTest.testFailure(MovieTest.java:24) at java.lang.reflect.Method.invoke(Native Method) 11/29/2018 SOEN 343, © P.Chalin,

18 Most Common: Testing For Expected Values
public void testEmptyVectorSize() { Vector v = new Vector(); assertEquals( “size should be 0”, // msg 0, // expected value v.size() // actual value ); } 11/29/2018 SOEN 343, © P.Chalin,

19 Other Assert Methods assertEquals(expected_value, actual_value)
i.e. no message provided. assertNull(reference_type_expr) assertNotNull(reference_type_expr) assertTrue(boolean_expr) assertFalse(boolean_expr) assertSame(expected_ref, actual_ref) 11/29/2018 SOEN 343, © P.Chalin,

20 JUnit Example, VectorTest Class
import junit.framework.TestCase; public class VectorTest extends TestCase { public void testEmptyVectorSize() { Vector v = new Vector(); assertEquals(0, v.size()); } 11/29/2018 SOEN 343, © P.Chalin,

21 UML Class Diagrams: Associations
Excerpt of UML Distilled handed out – I recommend you purchase it. Explained relationship between attributes and associations in class diagrams. 11/29/2018 SOEN 343, © P.Chalin,


Download ppt "SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin."

Similar presentations


Ads by Google