Download presentation
Presentation is loading. Please wait.
Published byMateo Betley Modified over 9 years ago
1
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Oriented Analysis, Design, and Programming
2
Mark Dixon, SoCCE 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 and use an object class
3
Mark Dixon, SoCCE SOFT 131Page 3 Evolution of Software Pressman (1992) page 5:
4
Mark Dixon, SoCCE SOFT 131Page 4 Software Crisis Customer (User) dissatisfaction: Over budget Late delivery Does not do what is required Poor quality –accuracy –reliability –maintainability –ease of use and learning Pressman (1992) p. 18
5
Mark Dixon, SoCCE SOFT 131Page 5 Example: Counter v1 Option Explicit Dim tmpCount As Long Private Sub Form_Load() tmpCount = 0 Me.lblCounter.Caption = tmpCount End Sub Private Sub btnUp_Click() tmpCount = tmpCount + 1 Me.lblCounter.Caption = tmpCount End Sub Private Sub btnDown_Click() tmpCount = tmpCount - 1 Me.lblCounter.Caption = tmpCount End Sub Private Sub btnReset_Click() tmpCount = 0 Me.lblCounter.Caption = tmpCount End Sub Counter v1
6
Mark Dixon, SoCCE SOFT 131Page 6 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
7
Mark Dixon, SoCCE SOFT 131Page 7 Example: Counter v2 Private Sub Form_Load() CounterReset CounterDisplay End Sub Private Sub btnUp_Click() CounterUp CounterDisplay End Sub Private Sub btnDown_Click() CounterDown CounterDisplay End Sub Private Sub btnReset_Click() CounterReset CounterDisplay End Sub Counter v2 Option Explicit Dim tmpCount As Long Sub CounterDisplay() Me.lblCounter.Caption = tmpCount End Sub Sub CounterReset() tmpCount = 0 End Sub Sub CounterUp() tmpCount = tmpCount + 1 End Sub Sub CounterDown() tmpCount = tmpCount - 1 End Sub
8
Mark Dixon, SoCCE SOFT 131Page 8 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
9
Mark Dixon, SoCCE SOFT 131Page 9 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
10
Mark Dixon, SoCCE SOFT 131Page 10 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
11
Mark Dixon, SoCCE SOFT 131Page 11 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
12
Mark Dixon, SoCCE SOFT 131Page 12 Implementation in VB class module – special type of module that defines an object class –Project menu, Add Class Module item Extends the record / structure / user defined data type, –which is used to store related data which may be of different types. An object stores –data –but also provides methods for accessing and manipulating that data. Animation
13
Mark Dixon, SoCCE SOFT 131Page 13 Modules/Units 1 Class per Module –keeps logically related things together –makes programming easier –less errors Example: Counter –Counter class put in separate module –main (form) module uses counter module
14
Mark Dixon, SoCCE SOFT 131Page 14 Example: Counter v3 Option Explicit Dim tmpCounter As Counter Private Sub Form_Load() Set tmpCounter = New Counter tmpCounter.Reset tmpCounter.Display Me.lblCounter End Sub Private Sub btnUp_Click() tmpCounter.Up tmpCounter.Display Me.lblCounter End Sub Private Sub btnDown_Click() … Private Sub btnReset_Click() tmpCounter.Reset tmpCounter.Display Me.lblCounter End Sub Private Sub Form_Unload (Cancel As Integer) Set tmpCounter = Nothing End Sub Counter v3 Option Explicit Private mCount As Long Public Sub Display(tmpLabel As Label) tmpLabel.Caption = mCount End Sub Public Sub Reset() mCount = 0 End Sub Public Sub Up() mCount = mCount + 1 End Sub Public Sub Down() mCount = mCount - 1 End Sub Counter (class module)
15
Mark Dixon, SoCCE SOFT 131Page 15 Things to Note The dot notation is the same for both records and objects. A record variable may be accessed immediately after definition whereas an object must first be ‘created’: Set tmpCounter = New Counter
16
Mark Dixon, SoCCE 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 Less prone to error
17
Mark Dixon, SoCCE SOFT 131Page 17 Why change? It’s well established that program quality improves as the semantic distance between the programming language and the real world problem language is diminished. It’s believed that the concept of communicating objects provides a better general framework for programming since it is closer to the real world situation than the structured paradigm.
18
Mark Dixon, SoCCE SOFT 131Page 18 Public Code As String Public Title As String Public Function GetTitle() As string Public Sub SetTitle(t As String) Public Function Count() As Integer Implementing Class Diagrams Module Code: String[7] Title: String[25] GetTitle(): string SetTitle(t: string) Count(): integer
19
Mark Dixon, SoCCE SOFT 131Page 19 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.
20
Mark Dixon, SoCCE SOFT 131Page 20 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.
21
Mark Dixon, SoCCE SOFT 131Page 21 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
22
Mark Dixon, SoCCE SOFT 131Page 22 Scenario 1: detail Nouns: drinks, order, cost Verbs: describe, calculate cost
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.