Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language...
Transcript of Object Oriented Programming · 3 Course goals Software design vs hacking Abstractions vs language...
![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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/18.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/20.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/22.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/23.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/25.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/26.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/27.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/28.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022070719/5edf4b50ad6a402d666aa504/html5/thumbnails/29.jpg)
29
Java applications:minimal Java programclass hello {
public static void main (String[] args) {
System.out.println(“Hello world!”);System.exit(0);
}}