Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!

Similar presentations


Presentation on theme: "Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!"— Presentation transcript:

1 Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!

2 Review Software development is an iterative and incremental process. OO software systems are systems of interacting objects. Objects have –properties (think of the counting object last class) –behaviors (think of the “jumping jack” object)

3 UML class diagrams (1) UML = Unified Modeling Language We use only class diagrams, not other UML diagrams Purpose: –keep OO concepts separate from implementation language –operate at a more abstract level than programming language, to avoid making implementation decisions when designing code

4 UML class diagrams (2) Class box –Class name –Properties –Behaviors Only as much detail as is needed Relationships –inheritance –implements –composition –dependency –association

5 UML class diagrams (3)

6 Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression: new chapter1.Terrarium ()

7 new chapter1.Terrarium() ‘new’ is a “reserved word” in Java. This means that the word ‘new’ has a special meaning in the Java language. ‘new’ is the name of an operator whose job it is to create an instance of a given class chapter1.Terrarium is the name of the class we are instantiating. It is a compound name, consisting of a package name (chapter1) and the name of the class’ constructor (Terrarium), separated by a dot ‘.’ A constructor initializes the state of a newly created object. The parentheses delimit the argument list of the constructor call. In this case there are no arguments being passed along to the constructor, so the argument list is empty.

8 Packages A package is an organizational mechanism One analogy: –package::class –area code::phone number A class’ fully qualified name consists of its package name and its (unqualified) class name: –chapter1.Terrarium is a fully qualified class name –Terrarium is an unqualified class name

9 On to Eclipse package lecture; class EcoSystem { public EcoSystem() { }

10 Syntax package lecture; public class EcoSystem { public EcoSystem() { } Package declaration is shown in green:

11 Syntax package lecture; public class EcoSystem { public EcoSystem() { } package is a reserved word:

12 Syntax package lecture; public class EcoSystem { public EcoSystem() { } lecture is the name of the package – you choose this (we’ll cover naming rules and conventions later):

13 Syntax package lecture; public class EcoSystem { public EcoSystem() { } A semicolon ‘;’ marks the end of the declaration:

14 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The class definition is shown in green:

15 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The class definition consists of a header...

16 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and a body:

17 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The class header consists of an access control modifier...

18 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... the reserved word class...

19 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and a class name:

20 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The class body begins with an opening brace ‘{’...

21 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and ends with the matching closing brace ‘}’ :

22 Syntax package lecture; public class EcoSystem { public EcoSystem() { } In this example, the body consists of a single constructor definition:

23 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The constructor definitons consists of a header...

24 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and a body:

25 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The constructor header consists of an access control modifier...

26 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... the constructor name (which is the same as the class name)...

27 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and a parameter list:

28 Syntax package lecture; public class EcoSystem { public EcoSystem() { } The constructor body begins with an opening brace ‘{’...

29 Syntax package lecture; public class EcoSystem { public EcoSystem() { }... and ends with the matching closing brace ‘}’ :


Download ppt "Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!"

Similar presentations


Ads by Google