+ All Categories
Home > Documents > Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language...

Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language...

Date post: 02-Jun-2020
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
29
Object Oriented Programming Autumn 2003
Transcript
Page 1: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

Object Oriented Programming

Autumn 2003

Page 2: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

2

Outline

Course organizationIntroductionJava overview

Page 3: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

3

Course goals

Software design vs hackingAbstractions vs language (syntax)Java used to illustrate conceptsNOT a course about JavaPrerequisites

knowledge of C, C++, or similarsome programming experience

Page 4: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

4

Staff

Lecturer: Timour Katchaounov([email protected])

Assistants (seminars, labs):Jesper Wilhelmsson([email protected])

Ruslan Fomkin([email protected])

E-mail subject: “OOP-HT03: xxx”

Page 5: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

5

Course resourcesAll course information (schedule, slides, etc.):http://www.csd.uu.se/datalogi/cmtrl/oop/ht03/

Course management system:Everyone should registerAccessible from university networkhttp://udblserv.it.uu.se:8080/oop_ht03

Page 6: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

6

Assignments

Voluntary Java assignmentAfter the lab assumed to ‘know’ Java

Pasture simulationFour assignments - 4 pointsExtra fifth assignment - 5 points

2 students per group

Page 7: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

7

LiteratureCourse:Barbara Liskov: Program Development in Java.

Java:Bruce Eckel: Thinking in Javawww.bruceeckel.comJava Language/API docs:

java.sun.comdeveloper.java.sun.comjava.sun.com/docs/books/tutorial

Page 8: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

8

Outline

Course organizationIntroductionJava overview

Page 9: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

9

Software design

Real systems are bigApache: ~50000 linesCommunicator 4: ~3 000 000 lines

Requires many people to cooperateHard to understand, develop, maintainNeed for methods to handle complexity

=> Decomposition and abstraction

Page 10: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

10

Decomposition

Decompose problems into sub-problemsSame level of detailIndependentCombined solve the original problem

Break up a system into modules

Page 11: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

11

Abstraction

Ignore details => focus on important propertiesSimplify the problemMany-to-one mappingExamples: sets, numbers, humansDesign:abstract -> decompose -> abstract -> …

Page 12: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

12

Abstraction methods

Abstraction by parameterizationignore identity, focus on common propertiesmodule reusability

Abstraction by specificationignore implementation, focus on functionModule independence

Page 13: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

13

Types of abstractions (1)

Procedural abstractionsabstract some operationIntroduce new operations

Data abstractionsSets of ‘similar’ objects and their operationsOperations are relatedIntroduce new data types

Page 14: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

14

Types of abstractions (2)

Iteration abstractionsIgnore item storage & retrieval details

Type hierarchiesGroup similar/related abstractionsAllow to ignore differencesSubtypes/supertypes

Page 15: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

15

Types of abstractions (3)Combined use of parameterization and specificationAbstraction is language independentAny programming language can be usedObject-oriented languages make things easierThe data abstraction is central for OO programming and design

Page 16: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

16

Outline

Course organizationIntroductionJava overview

Page 17: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

17

Java overview

Reference implementation by SUNPlatform independentCompiled into bytecode (kind of assembler)Programs run on a virtual machine JVMAutomatic memory management -garbage collection

Page 18: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

18

OO abstractions in JavaSpecification => interfaces, javadoc, assertionsParameterization => methods, classes

Data abstractions => classes & objectsProcedural abstractions => methodsIteration abstractions => loops (for, while, do), iteratorsType hierarchies => class inheritance

Page 19: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

19

Java programs

Consist of classes and/or an interfacesCollections of proceduresData abstractions

No global variables, no “free” functionsEach class in its own fileInterface and implementation in one file (no .h files)

Page 20: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

20

Classes

Consist of fields and methodspublic class Square extends Shape {

private float xCoordinate;…public void rotate(float degree) {…

}…}

Page 21: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

21

Java TypesClasses - system and user definedPrimitive types - system defined:

byte, short, int, long, (8,16,32,64 bit), boolean, char (16 bit), float, doublefor performanceCan be wrapped in classes

Arrays:Are objects<type>[] <name>;String names[];Can’t grow

Page 22: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

22

Objects and variablesData accessed through variablesContain objects (on heap) or values (on stack)Primitive and reference variablesObject creation - the new operatorEquality: ‘==‘ and ‘equals’Object identityMutability and sharingArray objects

Page 23: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

23

Class fieldsDescribe state of objects and classes<visibility> <type> <name> = <value>;public float xCoordinate = 74.3;Accessed through objectssomeObject.fieldNameStatic fileds - value shared by all class objectsstatic <visibility> <type> <name> = <value>;Accessed through class: someClass.fieldName

Page 24: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

24

Methods

Method declaration and creation<visibility> <return type> <name>(formal params)

{ body; }

Call semanticsexpr.someMethod(param1, …);

Class vs instance methodsConstructor methods

Initialize objectsUsed through new operator

Page 25: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

25

Packages

Group related classes and interfacesProvide for modularityClass/interface visibilityFully qualified names

Page 26: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

26

Known syntax

for, while, doswitchNo gotoNo pointers

Page 27: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

27

Java applications

Console applicationsGUI applicationsStandalone vs. applets

Page 28: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

28

Java applications:the main method

Entry point to run applicationsStatic public main(String[] args){…}One per class

testingalternative program versions

Page 29: Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

29

Java applications:minimal Java programclass hello {

public static void main (String[] args) {

System.out.println(“Hello world!”);System.exit(0);

}}


Recommended