Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Programming Paradigms and languages
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
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.
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 22 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Associations.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Constants, Arrays, & Structures.
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.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Iterative Execution.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 13 – Object Oriented Programming.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Enumerated Data-Types & Pass-by-reference.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
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.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
8-1 Chapter 8 Using User-Defined Data Types and Object Oriented Programming.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
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 1 18 – Web applications: Server-side code (ASP.Net)
Mark Dixon Page 1 18 – Web applications: Server-side code (ASP)
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
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.
Tutorial 6 The Repetition Structure
Mark Dixon, SoCCE SOFT 131Page 1 23 – Object Associations.
Applications Development
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
ME 142 Engineering Computation I Using Subroutines Effectively.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
ME 142 Engineering Computation I Using Subroutines Effectively.
Mark Dixon SOFT 131Page 1 12 – Object Oriented Analysis, Design, and Programming.
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Programming with Microsoft Visual Basic th Edition
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
31/01/ Selection If selection construct.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
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, SoCCE SOFT 131Page 1 25 – Soft 131 Examination Revision.
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.
A variable is a name for a value stored in memory.
12 – Object Oriented Programming
23 – Object Oriented Programming in ASP
Variables Data Types and Assignment
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association

Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the idea of datatypes some of the more subtle aspects of object oriented design (such as object associations) Objectives, by end of this week’s sessions, you should be able to: –use datatypes to make you programs more memory efficient and faster –create a project with several associated objects

Mark Dixon, SoCCE SOFT 131Page 3 Data Types Variant – all types of data –slow, memory hungry Boolean – true or false Integer – whole numbers ( to 32768) Long – whole numbers (large) Single – decimal numbers Double – decimal numbers (more precise) String – text Object – object instances

Mark Dixon, SoCCE SOFT 131Page 4 Data Type Selection Number ofe.g. 4 Integer/Long Rooms Heighte.g. 1.87m Single/Double Surnamee.g. Smith String Car Rege.g. XY55 ABC String

Mark Dixon, SoCCE SOFT 131Page 5 Using data types Variable declaration Dim x As Long Parameters Sub Thing(boo As String, y As Long) Functions Function IsTall() As Boolean

Mark Dixon, SoCCE SOFT 131Page 6 client-side vs. server-side code client-side code – only variant server-side code – all datatypes Dim x Dim y Dim s Dim b x = 23 y = 18.5 s = "Hello there" b = false Dim x As Long Dim y As Double Dim s As String Dim b As Boolean x = 23 y = 18.5 s = "Hello there" b = false

Mark Dixon, SoCCE SOFT 131Page 7 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, SoCCE SOFT 131Page 8 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, SoCCE SOFT 131Page 9 Object Concepts - Implementation Properties – implemented as –data structures (variables, arrays, and types). 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, SoCCE SOFT 131Page 10 Class Diagrams Used to describe structure of object classes: Module Code: string Title: string GetTitle(): string SetTitle(t: string) Count(): integer Class Attributes/Properties Class Operations/Methods Class Name

Mark Dixon, SoCCE SOFT 131Page 11 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 Less prone to error

Mark Dixon, SoCCE SOFT 131Page 12 Class Module Public Code As String Public Title As String Public Function GetTitle() As string Public Sub SetTitle(t As String) Public Function Count() As Integer End Class Implementing Class Diagrams Module Code: String Title: String GetTitle(): string SetTitle(t: string) Count(): integer

Mark Dixon, SoCCE SOFT 131Page 13 Public and Private Control access to properties and methods Class a Public x As Single Private y As Single End Class Dim b As New a b.x = 5 b.y = 10 this works (x is public)  this will fail (y is private)

Mark Dixon, SoCCE SOFT 131Page 14 Example: Counter (html) Counter page

Mark Dixon, SoCCE SOFT 131Page 15 Example: Counter (code) Dim c As Object Dim msg As String Sub Main() If Session("c") Is Nothing Then Session("c") = New Counter Else c = Session("c") If Request.Form("btnReset") <> "" Then c.Reset() ElseIf Request.Form("btnUp") <> "" Then c.Up() ElseIf Request.Form("btnDown") <> "" Then c.Down() End If msg = c.GetCount() End If End Sub Class Counter Private mCount As Long Public Function GetCount() As Long GetCount = mCount End Function Public Sub Reset() mCount = 0 End Sub Public Sub Up() mCount = mCount + 1 End Sub Public Sub Down() mCount = mCount - 1 End Sub End Class Counter.vbs

Mark Dixon, SoCCE SOFT 131Page 16 Object Associations In practice projects will be made of –many object classes –that interact with each other (are associated) There are several types of association One of the most often used is the ‘part of’ association, –where one object class forms part of another object class A common example of this occurs where it is necessary to store multiple instances of a class

Mark Dixon, SoCCE SOFT 131Page 17 Example: Bar (Analysis) Scenario 1: small project, limited automation –Nouns: drinks, order, cost –Verbs: describe, 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, SoCCE SOFT 131Page 18 Example: Bar (Design v1) Object Classes, properties, and methods –Class diagram: Order mDrinks(): Drink Add(string, long) Remove(long) Display (): String Cost(): double Drink mType: String mQty: Long

Mark Dixon, SoCCE SOFT 131Page 19 Example: Bar (Drink module) Drink (class module): Class Drink Public mType As String Public mQty As Long End Class Drink mType: String mQty: Long

Mark Dixon, SoCCE SOFT 131Page 20 Example: Bar (Order module) Class Order Private mDrinks(9) As Drink Public Sub Add(tmpType As String, tmpQty As Long) Dim d As Long ' Find free slot. For d = 0 To 9 If mDrinks(d) Is Nothing Then Exit For End If Next ' Create object and store data. mDrinks(d) = New Drink mDrinks(d).mType = tmpType mDrinks(d).mQty = tmpQty End Sub End Class Order mDrinks(): Drink Add(string, long) Remove(long) Display (): String Cost(): double

Mark Dixon, SoCCE SOFT 131Page 21 Example: Bar (Order module) method (procedure) to display order's drinks in a list box Public Function Display() As String Dim d As Long Dim tmpStr As String tmpStr = "" For d = 0 To 9 If Not (mDrinks(d) Is Nothing) Then tmpStr = tmpStr & mDrinks(d).mQty & " " tmpStr = tmpStr & mDrinks(d).mType End If Next Display = tmpStr End Function Order mDrinks(): Drink Add(string, long) Remove(long) Display (): String Cost(): double

Mark Dixon, SoCCE SOFT 131Page 22 Example: Bar (Order module) method (procedure) to remove drink from order Public Sub Remove(d As Long) mDrinks(d) = Nothing End Sub Order mDrinks(): Drink Add(string, long) Remove(long) Display (ListBox) Cost(): double

Mark Dixon, SoCCE SOFT 131Page 23 Tutorial Exercise: Bar Task 1: Get the Bar example from the lecture working. Task 2: Modify your code – add code to calculate the cost of the order. This object method is not in the lecture notes – you need to create it (not necessarily on your own – discuss it with others, feel free to ask me for help). Task 3: What happens if the user tries to add more than 10 drinks? Modify your code to cope with this (you decide how it should respond). Task 4: What happens if the user tries to add a drink when none is selected (in the drinks list box)? Modify your code to cope with this. Task 5: What happens if the user tries to remove a drink when none is selected (in the order list box)? Modify your code to cope with this. Task 6: Modify your code – so that the cost is continuously calculated and there is no need for the cost button.