Object Oriented Programming

Only available on StudyMode
  • Download(s) : 94
  • Published : June 22, 2012
Open Document
Text Preview
Object-Oriented Programming
School of Computer Science University of KwaZulu-Natal February 5, 2007

Object Oriented Programming using Java

Notes for the Computer Science Module Object Oriented Programming COMP200

Adapted from Introduction to Programming Using Java Version 5.0, December 2006 by David J. Eck http://math.hws.edu/javanotes/ Adapted by Anban Pillay School of Computer Science University of KwaZulu-Natal Durban February 2007

3

4

Contents

1 Introduction to Objects 1.1 What is Object Oriented Programming? . . . . . . . . . . . . . . 1.1.1 Programming Paradigms . . . . . . . . . . . . . . . . . . . 1.1.2 Object Orientation as a New Paradigm: The Big Picture 1.2 Fundamentals of Objects and Classes . . . . . . . . . . . . . . . 1.2.1 Objects and Classes . . . . . . . . . . . . . . . . . . . . . . 1.2.2 Class Members and Instance Members . . . . . . . . . . 1.2.3 Access Control . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.4 Creating and Destroying Objects . . . . . . . . . . . . . . 1.2.5 Garbage Collection . . . . . . . . . . . . . . . . . . . . . . 1.2.6 Everything is NOT an object . . . . . . . . . . . . . . . . . 2 The Practice of Programming 2.1 Abstraction . . . . . . . . . . . . . . . . . . . . . 2.1.1 Control Abstraction . . . . . . . . . . . . . 2.1.2 Data Abstraction . . . . . . . . . . . . . . 2.1.3 Abstraction in Object-Oriented Programs 2.2 Methods as an Abstraction Mechanism . . . . . 2.2.1 Black Boxes . . . . . . . . . . . . . . . . . 2.2.2 Preconditions and Postconditions . . . . . 2.2.3 APIs and Packages . . . . . . . . . . . . . 2.3 Introduction to Error Handling . . . . . . . . . . 2.4 Javadoc . . . . . . . . . . . . . . . . . . . . . . . . 2.5 Creating Jar Files . . . . . . . . . . . . . . . . . . 2.6 Creating Abstractions . . . . . . . . . . . . . . . 2.6.1 Designing the classes . . . . . . . . . . . . 2.7 Example: A Simple Card Game . . . . . . . . . . 3 Tools for Working with Abstractions 3.1 Introduction to Software Engineering . . . 3.1.1 Software Engineering Life-Cycles . . 3.1.2 Object-oriented Analysis and Design 3.1.3 Object Oriented design . . . . . . . . 3.2 Class-Responsibility-Collaboration cards . 3.3 The Unified Modelling Language . . . . . . 3.3.1 Modelling . . . . . . . . . . . . . . . . 5

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

11 11 12 14 16 16 22 27 29 34 35 37 37 38 39 39 40 40 41 42 46 49 51 52 52 58 63 63 63 64 65 66 67 67

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

3.3.2 3.3.3 3.3.4 3.3.5 3.3.6

Use Case Diagrams . . . Class Diagrams . . . . . Sequence Diagrams . . . Collaboration Diagrams State Diagram . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

68 69 73 73 74 77 77 80 81 83 86 88 88 89 90 93 93 96 98 99 100 101 105 106 107 109 111 112 113 113 115 117 119 121 122 123 124 126 129 130 131 134 137 139 140 140 141

4 Inheritance, Polymorphism, and Abstract Classes 4.1 Extending Existing Classes . . . . . . . . . . . ....
tracking img