Object-Oriented Programming
Total Page:16
File Type:pdf, Size:1020Kb
What is OOP (and why does it matter?) CAS London 2016 Michael Kölling University of Kent FLOW-MATIC 1957 ALGOL 58 FORTRAN I COMTRAN ALGOL 60 1960 FORTRAN II COBOL LISP FORTRAN IV CPL 1965 SIMULA I PL/1 BASIC SIMULA 67 BCPL 1970 B PROLOG PASCAL C SH 1975 ML SCHEME AWK 1980 MODULA 2 SMALLTALK 80 ERLANG PERL MIRANDA OBERON MODULA 3 ADA SELF OBJECTIVE C 1985 C++ EIFFEL HASKELL 1990 1995 VISUAL BASIC BLUE JAVA PYTHON PHP 2000 JAVASCRIPT RUBY C# SCALA F# 2005 DART Copyright (c) Michael Kölling, University of Kent, 2016 2010 FLOW-MATIC 1957 ALGOL 58 FORTRAN I COMTRAN ALGOL 60 1960 FORTRAN II COBOL LISP FORTRAN IV CPL 1965 SIMULA I PL/1 BASIC SIMULA 67 BCPL 1970 B PROLOG PASCAL C SH 1975 ML SCHEME AWK 1980 MODULA 2 SMALLTALK 80 ERLANG PERL MIRANDA OBERON MODULA 3 ADA SELF OBJECTIVE C 1985 C++ EIFFEL HASKELL 1990 1995 VISUAL BASIC BLUE JAVA PYTHON PHP 2000 JAVASCRIPT RUBY C# SCALA F# 2005 C-style syntax DART Copyright (c) Michael Kölling, University of Kent, 2016 2010 FLOW-MATIC 1957 ALGOL 58 FORTRAN I COMTRAN ALGOL 60 1960 FORTRAN II COBOL LISP FORTRAN IV CPL 1965 SIMULA I PL/1 BASIC SIMULA 67 BCPL 1970 B PROLOG PASCAL C SH 1975 ML SCHEME AWK 1980 MODULA 2 SMALLTALK 80 ERLANG PERL MIRANDA OBERON MODULA 3 ADA SELF OBJECTIVE C 1985 C++ EIFFEL HASKELL 1990 1995 VISUAL BASIC BLUE JAVA PYTHON PHP 2000 JAVASCRIPT RUBY C# SCALA F# 2005 FUNCTIONAL DART Copyright (c) Michael Kölling, University of Kent, 2016 2010 FLOW-MATIC 1957 ALGOL 58 FORTRAN I COMTRAN ALGOL 60 1960 FORTRAN II COBOL LISP FORTRAN IV CPL 1965 SIMULA I PL/1 BASIC SIMULA 67 BCPL 1970 B PROLOG PASCAL C SH 1975 ML SCHEME AWK 1980 MODULA 2 SMALLTALK 80 ERLANG PERL MIRANDA OBERON MODULA 3 ADA SELF OBJECTIVE C 1985 C++ EIFFEL HASKELL 1990 1995 VISUAL BASIC BLUE JAVA PYTHON PHP 2000 JAVASCRIPT RUBY C# SCALA F# 2005 DART OBJECT-ORIENTEDCopyright (c) Michael Kölling, University of Kent, 2016 2010 FLOW-MATIC 1957 ALGOL 58 FORTRAN I COMTRAN ALGOL 60 1960 FORTRAN II COBOL LISP FORTRAN IV CPL 1965 SIMULA I PL/1 BASIC SIMULA 67 BCPL 1970 B PROLOG PASCAL C SH 1975 ML SCHEME AWK 1980 MODULA 2 SMALLTALK 80 ERLANG PERL MIRANDA OBERON MODULA 3 ADA SELF OBJECTIVE C 1985 C++ EIFFEL HASKELL 1990 1995 VISUAL BASIC BLUE JAVA PYTHON PHP 2000 JAVASCRIPT RUBY C# SCALA F# 2005 DART OBJECT-ORIENTEDCopyright (c) Michael Kölling, University of Kent, 2016 2010 01 Machine code F5 E9 FF 03 A2 2B 33 65 92 6F C0 Copyright (c) Michael Kölling, University of Kent, 2016 LDA 01 Assembler STY F5 ADD E9 JMP FF 03 03 162 A2 43 2B 51 33 ‘A’ 65 ‘b’ 92 ‘G’ 6F ‘z’ C0 Copyright (c) Michael Kölling, University of Kent, 2016 Higher level programming - - - - - - - - - - — 010011010 - - - - - — - 100110100 - —- 001011010 - - — - - — - code data Copyright (c) Michael Kölling, University of Kent, 2016 Higher level programming – with types - - - - - - - - - - — int n - - - - - — - char c - —- float f - - — - - — - code data Copyright (c) Michael Kölling, University of Kent, 2016 Structured programming - —- - - - - - ——— - - - - - - — - —— - - — - - — - - - - - - - —- - —- - —- - - - - - - — - —— - —— - —— - - - - - - — - - - - - - - — - — - - - — - - — - code data Copyright (c) Michael Kölling, University of Kent, 2016 - - - - code - - - - - - — Object-oriented programming - - — — - —- data - ——— - —— - — —- - - - - - - - - - code - - - - code code - - - - - - - — - - - - - - — - - - - - — - - - — — - - — — - — — - —- data - ——— - —— - — —- - - - - - code - - - - - - - - code code - - - - - - — - - - - - - — - - - - - - — - - — — - - — — - - — — - —- data - ——— - —— - — —- - - - - - code - - - - code - - - - - - — - - - - - - — - - — — - - — — Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming - - - - code - - - - - - — - - — — - —- data - ——— - —— - — —- - - - - - code - - - - code - - - - - - — - - - - - - — - - — — - - — — Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming method Encapsulation - —- data - ——— (Information hiding) method - —— method - — —- - method Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming method Encapsulation - —- data - ——— (Information hiding) method - —— method - — —- - method Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming method - —- data - ——— method method - —— - — —- - method class Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming method - —- methoddata - ——— method method - ——- method —- datamethod - —- —-——— - - —- method method data - ——- —- - ——— data method method method- — - —-——— - method - —— method method - —— - — —- - - —- method- — —- - data - ——— method method method - —— method- — —- - class method instances (objects) Instantiation Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming method - —- data - ———method method method method - —— - —- - — —- - data - ———method method method 3333 - —— method method - —- 3333 method- — —- - data - ———method method method - —— - —- method- — —- - data method - ——— method method - —— method class - — —- - State method Behaviour instances (objects) Identity Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming Library Users name members student # Member visitors Member Member nameMember name ID #name ID #name Collection ID # ID # topic location Loan Loan Loan BookBook memberLoan Book member bookmember authorauthor bookmember author book titletitle book title Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming STUDENT name student # getName enrol Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming STUDENT STAFF name name student # office getName getName enrol pay Copyright (c) Michael Kölling, University of Kent, 2016 Object-oriented programming PERSON name Inheritance getName STUDENT STAFF student # office enrol pay Copyright (c) Michael Kölling, University of Kent, 2016 Modularisation Readability Maintainability Modelling Extendability Correctness Copyright (c) Michael Kölling, University of Kent, 2016 PRO: CON: Modularisation Boilerplate code Readability Strictness / inflexibility Maintainability Extendability Correctness Modelling Copyright (c) Michael Kölling, University of Kent, 2016 And now: How do I teach this? Copyright (c) Michael Kölling, University of Kent, 2016.