Mark Dixon SOFT 131Page 1 12 – Object Oriented Analysis, Design, and Programming.

Slides:



Advertisements
Similar presentations
Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Advertisements

When is Orientated Programming NOT? Mike Fitzpatrick.
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Mark Dixon Page 1 22 – Object Oriented Programming in ASP.
Mark Dixon Page 1 05 – Constants and Variables. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 mins short answer (5 - 6 words.
Mark Dixon, SoCCE SOFT 136Page 1 05 – Conditional Execution.
Mark Dixon Page 1 05 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Object Associations.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 10 – Variable Scope, and Arrays of Structures.
Mark Dixon Page 1 02 – Queries: Query by Example.
Visual Basic: An Object Oriented Approach 3 – Making Objects Work.
Mark Dixon Page 1 13 – Object Oriented Programming.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Constants and Variables.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Software Development
Mark Dixon Page 1 10 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of code to declare a variable called h Write a line of.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
An Object-Oriented Approach to Programming Logic and Design
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 07 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon Page 1 09 – Arrays. Mark Dixon Page 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon, SoCCE SOFT 136Page 1 9 – Procedures. Mark Dixon, SoCCE SOFT 136Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon Page 1 10 – Procedures. Mark Dixon Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved in grouping instructions,
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon 1 08 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Mark Dixon 1 14 – Functions and Modules. Mark Dixon 2 Questions: Parameters Consider the following code: Sub Move(ByRef obj, ByVal dist) obj.style.posLeft.
Mark Dixon 1 03 – Information Processing. Mark Dixon 2 Questions: Events Consider the following code: a) How many unique events does it contain? b) Name.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Definition of Object - Oriented Language.. Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions"
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Learners Support Publications Object Oriented Programming.
Mark Dixon Page 1 8 – Procedures. Mark Dixon Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved in grouping instructions,
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Mark Dixon, SoCCE SOFT 131Page 1 18 – Enumerated Data Types and Arrays of Structures.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
Mark Dixon 1 15 – Structured Programming. Mark Dixon 2 Admin: Test 2 In class test –11 Feb 2014 –4 Feb 2014: revision (technique) session 50 mins short.
Mark Dixon 1 13 – Parameters. Mark Dixon 2 Question: Arrays How many array variables are in the following code: Dim x Dim y Dim f(4) x = 12 y = 6 f(2)
Mark Dixon 1 Soft051 Examination Sample Questions.
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Conditional Execution.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-Orientated Programming
15 – Structured Programming
12 – Object Oriented Programming
23 – Object Oriented Programming in ASP
Presentation transcript:

Mark Dixon SOFT 131Page 1 12 – Object Oriented Analysis, Design, and Programming

Mark Dixon SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the fundamental ideas of object orientation Objectives, by end of this week’s sessions, you should be able to: –create a class definition, which includes properties, and methods –create an object instance, for the class –use the object instance, by assigning values to its properties, and calling its methods

Mark Dixon SOFT 131Page 3 Example: Ball Bounce v1 Ball Bounce Option Explicit Dim x Dim y Dim xInc Dim yInc Sub window_onLoad() window.setinterval "Main", 20 xInc = 5 yInc = 3 End Sub Sub Main() x = imgBall.style.pixelLeft + xInc If x = document.body.clientWidth - imgBall.width Then xInc = -xInc Else imgBall.style.pixelLeft = x End If y = imgBall.style.pixelTop + yInc If y = document.body.clientHeight - imgBall.height Then yInc = -yInc Else imgBall.style.pixelTop = y End If End Sub

Mark Dixon SOFT 131Page 4 Structured Paradigm Program made up of –data structures, and –routines (procedures and functions) that process the data within those structures. Each routine should perform a single, clearly identifiable operation. Each routine should be self-contained Go to statements replaced by structures Abstract data type = structure + procedures

Mark Dixon SOFT 131Page 5 Example: Ball Bounce v2 Option Explicit Dim x Dim y Dim xInc Dim yInc Sub Init(tmpXInc, tmpYInc) xInc = tmpXInc yInc = tmpYInc End Sub Sub Move(img) x = img.style.pixelLeft + xInc If x = document.body.clientWidth - img.width Then xInc = -xInc Else img.style.pixelLeft = x End If y = img.style.pixelTop + yInc If y = document.body.clientHeight - img.height Then yInc = -yInc Else img.style.pixelTop = y End If End Sub Ball Bounce Option Explicit Sub window_onLoad() window.setinterval "Main", 20 Init 5, 3 End Sub Sub Main() Move imgBall End Sub BallBounce.htm Sprit.vbs

Mark Dixon SOFT 131Page 6 Object-Oriented Paradigm A program is made up of a number of objects that communicate with each other by passing messages Each object contains –attributes/properties that represent its state, and –operations/methods that represent its behaviour Objects often mirror the real world –Customers –Students –Patients

Mark Dixon SOFT 131Page 7 Classes and Instances Object Classes –general descriptions of types of objects, e.g. student, product, customer, lecturer, and room. Object Instances –specific items of a given class, e.g. each of you could be an instance of the student class Room 214 could be an instance of the room class I could be an instance of the lecturer class Bolt could be an instance of the part class

Mark Dixon SOFT 131Page 8 Object Concepts - Implementation Properties – implemented as –data structures (variables, and arrays) Methods – implemented as either –a procedure (to perform some processing), or –a function (to return a value) Object oriented paradigm builds on (rather than replaces) the structured paradigm

Mark Dixon SOFT 131Page 9 Properties: Animals Class: Animal Properties: Name, Species, Gender Instances: myPet, yourPet

Mark Dixon SOFT 131Page 10 Example: Ball Bounce v3 Option Explicit Class Sprite Dim x Dim y Dim xInc Dim yInc End Class Sub Init(spr, tmpXInc, tmpYInc) spr.xInc = tmpXInc spr.yInc = tmpYInc End Sub Sub Move(spr, img) spr.x = img.style.pixelLeft + spr.xInc If spr.x = document.body.clientWidth - img.width Then spr.xInc = -spr.xInc Else img.style.pixelLeft = spr.x End If spr.y = img.style.pixelTop + spr.yInc If spr.y = document.body.clientHeight - img.height Then spr.yInc = -spr.yInc Else img.style.pixelTop = spr.y End If End Sub … Option Explicit Dim ball Sub window_onLoad() window.setinterval "Main", 20 Set ball = New Sprite Init ball, 5, 3 End Sub Sub Main() Move ball, imgBall End Sub BallBounce.htm Sprit.vbs Class Definition

Mark Dixon SOFT 131Page 11 Methods: Students Method: Clear

Mark Dixon SOFT 131Page 12 Example: Ball Bounce v4 Option Explicit Class Sprite Dim x Dim y Dim xInc Dim yInc Sub Init(tmpXInc, tmpYInc) xInc = tmpXInc yInc = tmpYInc End Sub Sub Move(img) x = img.style.pixelLeft + xInc If x = document.body.clientWidth - img.width Then xInc = -xInc Else img.style.pixelLeft = x End If y = img.style.pixelTop + yInc If y = document.body.clientHeight - img.height Then yInc = -yInc Else img.style.pixelTop = y End If End Sub End Class … Option Explicit Dim ball Sub window_onLoad() window.setinterval "Main", 20 Set ball = New Sprite ball.Init 5, 3 End Sub Sub Main() ball.Move imgBall End Sub BallBounce.htm Sprit.vbs

Mark Dixon SOFT 131Page 13 Example: Ball Bounce v5 Multiple instances:

Mark Dixon SOFT 131Page 14 Example: Ball Bounce v5 Ball Bounce Option Explicit Dim ball Dim face Sub window_onLoad() window.setinterval "Main", 20 Set ball = New Sprite ball.Init 5, 3 Set face = New Sprite face.Init 1, 12 End Sub Sub Main() ball.Move imgBall face.Move imgFace End Sub Now have easy way of: –creating & using multiple sprites –each with own identity (separate characteristics) –only a few (4) lines of code

Mark Dixon SOFT 131Page 15 Questions: OOP Name a –class –property –method –instance Class House Dim number Dim road Dim district Sub ChangeDist(newDist) district = newDist End Sub End Class Dim h Set h = New House

Mark Dixon SOFT 131Page 16 Benefits of OOP in code Procedures and Functions are part of object –encapsulation Related Data and Operations together Private keyword – restrict access to data Clearer code Reduces chance of accidental interference Less prone to error

Mark Dixon SOFT 131Page 17 Object Oriented Analysis Look for nouns in text, either –object classes, or –object properties Look for verbs in text, –object methods The students' Union bar needs a computer system for recording the purchase of drinks. Typically, a student will stagger to the bar and describe their order, consisting of one or (usually) more drinks. The bar staff will then prepare the drinks and calculate the cost of the order.

Mark Dixon SOFT 131Page 18 Identify all nouns and verbs Nouns: student's Union bar, computer system, drinks, student, bar, order, bar staff, cost. Verbs: recording the purchase, stagger, describe, prepare drinks, calculate cost The students' Union bar needs a computer system for recording the purchase of drinks. Typically, a student will stagger to the bar and describe their order, consisting of one or (usually) more drinks. The bar staff will then prepare the drinks and calculate the cost of the order.

Mark Dixon SOFT 131Page 19 Identify relevant nouns and verbs What is relevant? –depends on project scope, duration, budget Scenario 1: small project, limited automation –Nouns: drinks, order, cost –Verbs: describe, calculate cost Scenario 2: large project, high automation –Nouns: student's Union bar, drinks, student, bar, order, bar staff, cost. –Verbs: recording the purchase, describe, prepare drinks, calculate cost

Mark Dixon SOFT 131Page 20 Scenario 1: detail Nouns: drinks, order, cost Verbs: describe, calculate cost

Mark Dixon SOFT 131Page 21 Tutorial Exercise: Ball Bounce Learning Objective: To create and use your own class. Task 1: Get the Ball Bounce examples (1, 2, and 5) from the lecture working. Task 2: Add a hit method to the sprite class, which detects the collision with another sprite. Task 3: Modify your page to count the number of hits between the two sprites. Task 4: Modify your page to make sprites bounce off each other. Task 5: Add another sprite.

Mark Dixon SOFT 131Page 22 Tutorial Exercise: Bar Task 1: Continue the analysis of the bar example in the lecture, and implement a simple object oriented bar drinks calculation program.

Mark Dixon SOFT 131Page 23 Tutorial Exercise: Interceptor Learning Objective: To create and use your own classes. Task 1: Re-write your Interceptor example (from last week) to use object oriented concepts (classes, properties, methods, and instances)