1 / 25

22 – Object Oriented Analysis, Design, and Programming

22 – Object Oriented Analysis, Design, and Programming. 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. Evolution of Software. Pressman (1992) page 5:.

ciaran-wolf
Download Presentation

22 – Object Oriented Analysis, Design, and Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 22 – Object Oriented Analysis, Design, and Programming

  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. Evolution of Software Pressman (1992) page 5:

  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. 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. 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. Example: 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 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

  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. 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. 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. Class Diagrams • Used to describe structure of object classes: Class Name Module Code: string Title: string Class Attributes/Properties GetTitle(): string SetTitle(t: string) Count(): integer Class Operations/Methods

  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. OOP: Animation

  14. 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

  15. 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 (class module) 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 v3

  16. 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

  17. Benefits of OOP in code • Procedures and Functions are part of object • encapsulation • RelatedData and Operationstogether • Private keyword – restrict access to data • Clearer code • Less prone to error

  18. 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.

  19. Implementing Class Diagrams Module Code: String[7] Title: String[25] GetTitle(): string SetTitle(t: string) Count(): integer Public Code As String Public Title As String Public Function GetTitle() As string Public Sub SetTitle(t As String) Public Function Count() As Integer

  20. 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.

  21. Identify all nouns and verbs 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. • Nouns: student's Union bar, computer system, drinks, student, bar, order, bar staff, cost. • Verbs: recording the purchase, stagger, describe, prepare drinks, calculate cost

  22. 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

  23. Scenario 1: detail • Nouns: drinks, order, cost • Verbs: describe, calculate cost

  24. Tutorial Exercise: Counter • Learning Objective: The important thing to understand from this exercise is that using classes allows you to make data private, and therefore prevents it being accidentally changed by other modules. • Task 1: Get the Counter examples (1, 2, and 3) from the lecture working. • Task 2: Modify your code (for v3) – add code to prevent the counter going below zero. • Task 3: Modify your code (for v3) – add code to prevent the counter going above ten. • Task 4: Modify your code (for v3) – add code for two additional properties max and min, that are used by the above limits.

  25. 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.

More Related