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 1b Review of Object-Oriented Programming (OOP) fundamentals. Basic UML: a language for expressing designs. 11/30/2018 SOEN 343, © P.Chalin,

3 Reminders Tutorial to be held in H-905. You will have to buddy up …
11/30/2018 SOEN 343, © P.Chalin,

4 What is design? Requirements vs. Design: what vs. how.
In design we create a system that will offer services to customers based on their statement of requirements. Course: Object-oriented analysis and design. Hence familiarity with OO programming is essential. 11/30/2018 SOEN 343, © P.Chalin,

5 Object-Oriented Programming
11/30/2018 SOEN 343, © P.Chalin,

6 OOP Reference Program Development in Java: Abstraction, Specification, and Object-oriented Design by Liskov and Guttag. AW 2001. Much of what follows is summarized from this book. 11/30/2018 SOEN 343, © P.Chalin,

7 Object-oriented languages: basic notions
Basic notions: object, classes. Every object is an instance of a class. Most data is contained in objects. Objects contain both state and operations Operations are called methods. Objects interact by invoking methods. Methods allow the objects state to be accessed and possibly changed. 11/30/2018 SOEN 343, © P.Chalin,

8 Objects Have secrets Offer services to other objects in its community.
They can hide e.g. data or even algorithm details. Offer services to other objects in its community. 11/30/2018 SOEN 343, © P.Chalin,

9 Java Programs Consist of classes and interfaces.
A class can be used to Hold collections of procedures (static methods), or Define new data types. Interfaces can also be used to define new types. 11/30/2018 SOEN 343, © P.Chalin,

10 Methods Most of the text in a class or interface file will consists of method definitions. Methods can accept parameters and return results. Arguments are passed by “value”. 11/30/2018 SOEN 343, © P.Chalin,

11 Packages TBC later. 11/30/2018 SOEN 343, © P.Chalin,

12 Objects and Variables All data is access by means of variables.
Local variables (including method parameters) are allocated on the runtime stack. Every variable has a declared type that is either Primitive type (int, char). Reference type (int [], String, any class type). Variables of Primitive types contain values. Reference types contain references to objects that are stored in the system heap. 11/30/2018 SOEN 343, © P.Chalin,

13 Stack and Heap Heap Stack [2,1,0] i j a b 3 s t SOEN 343, © P.Chalin,
11/30/2018 SOEN 343, © P.Chalin,

14 Stack and Heap: Exercise
Given the following declarations int i = 6; int j; int a[] = {1,2,3}; int[] b = new int[2]; String s = “abc”; String t = null; what will be the state of the stack and heap after they have all been processed? 11/30/2018 SOEN 343, © P.Chalin,

15 Stack and Heap Stack Heap i j a b s t 11/30/2018 SOEN 343, © P.Chalin,

16 Type Hierarchy Every class is a subclass of Object.
If S is a subclass of T then we can use an instance of S where ever a T is expected: T t = new S(); Object o = new S(); Object o = new String(“abc”); 11/30/2018 SOEN 343, © P.Chalin,

17 Method Invocations & Field Access
static non-static 11/30/2018 SOEN 343, © P.Chalin,

18 Static Methods & Fields
The method called depends on the declared type of the variable (not the run-time type of the referenced object). Like a “global” procedure and/or variable. 11/30/2018 SOEN 343, © P.Chalin,

19 Class P – i.e. Parent class
class P { static int rate = 1; static String m1() {return “P.m1”} static String m2() { ... } String r1() {… "P.r1:“ + rate;} String r2() { … } } 11/30/2018 SOEN 343, © P.Chalin,

20 Class C – i.e. Child class class C extends P { static int rate = 2; static String m1() {return “C.m1”} String r1() {… “C.r1:"+rate;} } 11/30/2018 SOEN 343, © P.Chalin,

21 Main Class, part I P p = new C(); println(p.m1()); println(p.m2());
println(p.r1()); println(p.r2()); println(p.rate); 11/30/2018 SOEN 343, © P.Chalin,

22 Main Class, part II C c = new C(); println(c.m1()); println(c.m2());
println(c.r1()); println(c.r2()); println(c.rate); 11/30/2018 SOEN 343, © P.Chalin,

23 Dynamic Dispatching Now consider String s = “abc”; Object o = s;
… o.equals(s); 11/30/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