Visual Basic: An Object Oriented Approach 6: Object Modelling.

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Integrated Business Applications with Databases (D3) Jenny Pedler
8 – Objects as building blocks Visual Basic: An Object Oriented Approach.
Dr Terry Hinton 28/10/03 CSM18 VB OOP1 Visual Basic: An Object Oriented Approach Programming is a Model of the Real World Object in Real World modelled.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Visual Basic: An Object Oriented Approach 2 – Designing Software Systems.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Ch 12: Object-Oriented Analysis
Lecture 8 Electronic Commerce Modelling Techniques
Sequence Diagrams. Introduction A Sequence diagram depicts the sequence of actions that occur in a system. The invocation of methods in each object, and.
ATM User Interface Design. Requirements A bank customer is able to access his or her account using an automatic teller machine. To be able to use an ATM.
Interaction Diagrams Activity Diagram State Machine Diagram
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Visual Basic: An Object Oriented Approach 10 - Polymorphism.
Object Oriented Analysis Process
8 – Objects as building blocks Visual Basic: An Object Oriented Approach.
Visual Basic: An Object Oriented Approach 3 – Making Objects Work.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
ASP.NET Programming with C# and SQL Server First Edition
ACSE th Conference The Iconic Programmer Stephen Chen.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
Chapter 9 Domain Models 1CS6359 Fall 2012 John Cole.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
1 CSC103: Introduction to Computer and Programming Lecture No 13.
Module 7: Object-Oriented Programming in Visual Basic .NET
Visual Basic: An Object Oriented Approach 5: Structured Programming.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
CS212: Object Oriented Analysis and Design Lecture 4: Objects and Classes - I.
Chapter 4: The Selection Process in Visual Basic.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
1 Object-Oriented Analysis Use Case Driven. 2 The outline method for OOA 1.Identify object classes within the problem domain 2.Define the behaviour of.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Introduction to Objects MIS 3501: Management Information Systems Paul Weinberg Adapted from material by David Schuff, and Paul Weinberg.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Visual Basic Programming
Lecture OO05 Object Scenarios Object Interaction Diagrams
Information Systems Engineering Interaction Diagrams: Sequence Diagram Collbortion Diagram.
Introduction to Java Java Translation Program Structure
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Chapter 4 Introduction to Classes, Objects, Methods and strings
I Power Higher Computing Software Development High Level Language Constructs.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Inf 43: Introduction to Software Engineering May 7, 2016.
Object-Oriented Programming: Classes and Objects
draw a sequence diagram
Appendix D: Network Model
Object-Oriented Programming: Classes and Objects
CS285 Introduction - Visual Basic
Software Engineering System Modeling Chapter 5 (Part 1) Dr.Doaa Sami
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Lecture Set 9 Arrays, Collections, and Repetition
Presentation transcript:

Visual Basic: An Object Oriented Approach 6: Object Modelling

OOP – The Basics Revised Classes – templates for objects Encapsulation – separation of internal workings from external interface Properties – attributes of an object Methods – operations definValidateed for a class of objects Messages – interactions between objects

Object Models Real programs will involve large numbers of objects Will interact in various ways Will form logical structures May involve several levels of structure in complex systems Key to maintaining coherence is in building an object model that provides a ‘world view’ of the system

Use-Case Diagrams Used to obtain a high level (user-level) picture of the system Can be used in discussions with clients Shows main interactions between system and users/external environment ATM - Bank Machine Accept Card Verify PIN Print Statement Withdraw Cash Deposit Cash User (Actor)

Class Model based on Use-Case Diagram Having identified classes, need to define… Interactions between them Structure Class Interfaces ATM ValidateUser PrintStatement DoDeposit DoWithdrawal Account Balance PIN Owner Deposit Withdraw Statement :ATM:Account :Deposit(50)

Coding a Class Need to… Determine storage needs (member variables) Include structural relationships – e.g. An Account owns a collection of Transactions Implement Methods and Properties in terms of accesses to member variables Consider mechanisms for getting info to and from and object Properties (the obvious) Parameters to Subs and Functions (can apply multiple values at once) Results of Functions

Coding Classes Start from class lowest in structure/hierarchy Likely that higher up classes will have these as components Easier to test Build then test each class First individually, then With classes it interacts with, then In sub-system Have test data ready Best to consider testing during design phases Store test data and revise/reuse as necessary

Example – Bank/ATM Assume two classes only ATM Class models Teller machine Account class models individual account Start with Account class From Use-Case point of view, ATM accesses Account and is therefore controller Can build and test this class before moving on to ATM (which needs a working account to enable a full test) Decide on tests necessary based on Use-Case diagram Be prepared to change Use-Case, structure etc. as whole picture unfolds.

Account Class Private mvarBalance As Currency ‘ Unrealistic, but will do for example Private mvarPIN As Integer Private mvarOwner As String Public Property Get Balance() As Currency… Public Property Get PIN() As Integer… Public Property Let PIN(newValue As Integer)… Public Property Get Owner() As String… Public Property Let Owner(newValue As String)… Public Sub Deposit(amount As Currency)… Public Sub Withdraw(amount As Currency)… Public Function Statement() As String… Private mvarBalance As Currency ‘ Unrealistic, but will do for example Private mvarPIN As Integer Private mvarOwner As String Public Property Get Balance() As Currency… Public Property Get PIN() As Integer… Public Property Let PIN(newValue As Integer)… Public Property Get Owner() As String… Public Property Let Owner(newValue As String)… Public Sub Deposit(amount As Currency)… Public Sub Withdraw(amount As Currency)… Public Function Statement() As String… Whole Property and Method code not shown here. See samples next, and exercises in chapters 2 and 7 for complete code. Mostly, the code is Simple and obvious.

Account – Sample Property and Method Public Property Get Balance() As Currency Balance = mvarBalance End Property Public Property Get PIN() As Integer PIN = mvarPIN End Property Public Property Let PIN(newValue As Integer) mvarPIN = newValue End Property Public Sub Deposit(amount As Currency) mvarBalance = mvarBalance + amount End Sub Public Property Get Balance() As Currency Balance = mvarBalance End Property Public Property Get PIN() As Integer PIN = mvarPIN End Property Public Property Let PIN(newValue As Integer) mvarPIN = newValue End Property Public Sub Deposit(amount As Currency) mvarBalance = mvarBalance + amount End Sub Read-only property Read-write property Method definition

Testing Account Set A = New Account A.Owner = “Fred Bloggs” A.PIN = “1234” A.Deposit Print A.Statement Statement for: Fred Bloggs Balance = £ A.Withdraw 50 Print A.Statement Statement for: Fred Bloggs Balance = £ ‘ etc… Set A = New Account A.Owner = “Fred Bloggs” A.PIN = “1234” A.Deposit Print A.Statement Statement for: Fred Bloggs Balance = £ A.Withdraw 50 Print A.Statement Statement for: Fred Bloggs Balance = £ ‘ etc… In VB can use the Immediate Window to test a class Create an object Execute methods Print property values (Using Print or ?) Can also copy, the sequence of test statements, paste into Notepad or an editor, and save for re-testing if changes are made.

Continue Development Can go up hierarchy to create next class (ATM) Now possible to test ATM since Account class is in place ATM class must create an Account object to interact with User-Interactions with ATM should translate to ATM interactions with Account

Example ATM Method Public Function ValidateUser(A As Account) As Boolean Dim userPIN As Integer userPIN = InputBox(“Enter PIN”) If A.PIN = userPIN Then Set mvarCurrentAccount = A ValidateUser = True Else ValidateUser = False End If End Property Public Function ValidateUser(A As Account) As Boolean Dim userPIN As Integer userPIN = InputBox(“Enter PIN”) If A.PIN = userPIN Then Set mvarCurrentAccount = A ValidateUser = True Else ValidateUser = False End If End Property This method depends on the Account A being Available. Success of method leads to ATM Storing a reference to the Account.

Testing an ATM Method Set A = New Account A.Owner = “Fred Bloggs” A.PIN = “1234” Set ATM = New ATM Print ATM.ValidateUser A ‘ VB creates an InputBox() here to enter PIN number ‘ ATM returns True or False depending on input to it. ‘ Could now have ATM performing deposits and ‘ withdrawals etc. e.g… ATM.Deposit ATM.PrintStatement Statement for: Fred Bloggs Balance = £ Set A = New Account A.Owner = “Fred Bloggs” A.PIN = “1234” Set ATM = New ATM Print ATM.ValidateUser A ‘ VB creates an InputBox() here to enter PIN number ‘ ATM returns True or False depending on input to it. ‘ Could now have ATM performing deposits and ‘ withdrawals etc. e.g… ATM.Deposit ATM.PrintStatement Statement for: Fred Bloggs Balance = £100.00

References A Reference is a variable that acts as an alias for an object VB uses references exclusively for interacting with objects An object with no references to it is destroyed automatically When an object is created, a reference to it is assigned to an object variable As a consequence of this, an object can have any number of references to it.

References and Objects Set A = New Account Creates object Assigns reference A Account Object A2 Set A2 = A

Collections A Collection maintains a list of object references Therefore no need to maintain individual reference variables to prevent objects from being destroyed Acts as an unbounded array – no need to indicate how many elements to accommodate A collection is itself an object Can create collections of collections

Collection Methods Four main methods Add – adds an object reference to the collection Remove – removes a reference Count – returns number of references in the collection Item – a virtual array in the collection – allows access to object references Indexing Objects can be retrieved by number Objects can be added with a Key (string), which acts as a textual index

A Collection Set C = New Collection Set A = New Account A.Owner = “Fred” C.Add A Set A = New Account A.Owner = “Mary” C.Add A, “Second account” Print C.Count 2 Print C(1).Owner Fred Print C(“Second Account”).Owner Mary Set C = New Collection Set A = New Account A.Owner = “Fred” C.Add A Set A = New Account A.Owner = “Mary” C.Add A, “Second account” Print C.Count 2 Print C(1).Owner Fred Print C(“Second Account”).Owner Mary

Collections and For Each… Collections and objects introduce a new style of For..Next loop For Each A In C: Print A.Owner: Next Fred Mary For Each A In C: Print A.Owner: Next Fred Mary