Programming 2: Object-Oriented Programming With Java
Programming 2: Object-Oriented Programming With Java
Oscar Nierstrasz
double size() {
double total = 0;
for (Shape shape : shapes) {
total += shape.size();
}
return total;
(10,12)
}
(5,9)
(6,6)
(12,3)
(3,3)
P2 — Object-Oriented Programming
2
Roadmap
3
Roadmap
4
Your Learning Targets
Skills
You use your IDE, Debugger efficiently and effectively
5
The Big Picture
EI DA
P1 P2 ESE PSE …
DB MMS
6
Recommended Texts
1. Introduction
2. Object-Oriented Design Principles
3. Design by Contract
4. A Testing Framework
5. Debugging and Tools
6. Iterative Development
7. Advanced Design Lab
8. Inheritance and Refactoring
9. GUI Construction
10.Guidelines, Idioms and Patterns
11.A bit of Smalltalk
12.A bit of C++
13.Guest Lecture — Software-Entwicklung in der Praxis
8
This is a note (a hidden slide). You will find some of these
scattered around the PDF versions of the slides.
Plagiarism
Don’t copy!
The purpose of
exercises is training.
Copying answers
defeats this purpose!
NB: Plagiarism
is a serious
offense and is
not tolerated. 10
Please consult the U Bern guidelines and regulations:
http://www.unibe.ch/universitaet/organisation/rechtliches/rechtssammlung/
reglemente_richtlinien_weisungen_der_universitaetsleitung/
wissenschaftliche_integritaet/index_ger.html
Roadmap
11
What is the hardest part of programming?
What constitutes programming?
13
Roadmap
14
Three views of OO
16
Programs are executable models that are used to achieve some
effect in the real world. With a good design, the program code
reflects clearly the models as we want them to be.
Conceptual hierarchy,
Inheritance polymorphism and reuse
17
Encapsulation means that related entities are bundled together,
for example, a Shape object encapsulates data and related
operations for shapes.
Abstraction means that we ignore irrelevant details, for example,
we abstract from the details of a Shape object and just use its
interface (i.e., its operations).
Information hiding means that we hide (forbid access to) the
representation behind an abstraction, for example, you may not
directly access the state of a Shape but must access it only
through its interface.
These three concepts are closely related, but clearly different.
Composition refers to the fact that we can compose complex
objects from simpler ones. A Picture may be composed of many
shapes.
(10,12)
(5,9)
double size() {
double total = 0;
for (Shape shape : shapes) {
total += shape.size();
}
return total; public class Square extends Shape {
} ...
public double size() {
return width*width;
}
}
21
Object-Oriented Design in a Nutshell
22
Responsibility-Driven Design
23
Cohesion refers to the notion that related entities should be close
together. This is supported by encapsulation mechanisms, like
classes and packages. A good design is cohesive, so that when
you have to change something or add new features, then the parts
to change can be found together.
24
Extreme Programming
25
Testing
26
Code Smells
27
Refactoring
Example
> Adapter — “adapts one interface for a class into one that a client
expects.”
Patterns:
> Document “best practice”
> Introduce standard vocabulary
> Ease transition to OO development
But …
> May increase flexibility at the cost of simplicity
29
We will see several design patterns during the course, but we’ll
only look in detail near the end. Most of the design patterns we
will see are described in the classic book by the “Gang of Four.”
An electronic version is available to students of this course.
Roadmap
30
Why Java?
Special characteristics
> Resembles C++ minus the complexity
> Clean integration of many features
> Dynamically loaded classes
> Large, standard class library
1950
FORTRAN
ALGOL 60 LISP
1960 COBOL
PL/1
Simula 67
ALGOL 68
1970
Pascal
Smalltalk 72 C Prolog
Clu
awk
Modula-2
1980
Smalltalk 80
C++ Ada
Eiffel Oberon
Objective C Self Perl
1990
Python
Java
JavaScript Ruby php Ada 95
Squeak
2000
C#
Groovy
Pharo 32
2010
Java adopts much of its syntax from C++, to make it appeal to
seasoned C++ programmers, but adopts many language features
from Smalltalk, such as single inheritance, implementation based
on a virtual machine, and automatic garbage collection.
Roadmap
33
Programming Tools
34
Version Control Systems
35
Version Control
36
What you should know!
37
Can you answer these questions?
38
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
The licensor cannot revoke these freedoms as long as you follow the license terms.
Attribution — You must give appropriate credit, provide a link to the license, and indicate if
changes were made. You may do so in any reasonable manner, but not in any way that
suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your
contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally
restrict others from doing anything the license permits.
http://creativecommons.org/licenses/by-sa/4.0/