Object-Oriented Analysis and Design - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Object-Oriented Analysis and Design

Description:

... Problems Search routine does not work Should use constants or enums instead of strings Search should return multiple guitars ... Diagrams Basic Airplane Class ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 28
Provided by: TomPe70
Category:

less

Transcript and Presenter's Notes

Title: Object-Oriented Analysis and Design


1
Object-Oriented Analysis and Design
  • Introduction
  • Tom Perkins

2
  • Head First Object-Oriented Analysis and Design

by Brett McLaughlin, Gary Pollice, David West
Publisher O'Reilly
Pub Date November 2006
Print ISBN-10 0-596-00867-8
Print ISBN-13 978-0-59-600867-3
Pages 634
3
Head First Chapters
  1. Great Software Begins Here
  2. Gathering Requirements
  3. Requirements Change
  4. Analysis
  5. Handling Change
  6. Small Changes lead to Big Problems
  7. Incorporating Flexibility
  8. Software Architecture
  9. Bringing Order to Chaos
  10. Design Principles
  11. Iterating and Testing
  12. An OOAD Software Process

4
Obstacles
  • Not the perfect Introduction to Object
    Orientation book
  • Examples in Java
  • Rework in VB.NET or C.NET
  • Approach too Juvenile
  • Maybe
  • Incorporates many different features drawn from
    learning theory and cognitive psychology
  • Not a course for object oriented gurus
  • Yet assumes some familiarity with object-oriented
    coding
  • Major problem Getting you involved!

5
Approach
  • Stick close to the book
  • As much code as possible
  • Walkthrus
  • Get your hands dirty, become involved
  • Do the book exercises
  • Work with someone where possible
  • Participate in class discussions
  • Team Learning Experiments

6
Welcome to Objectville
  • Foist, youse gotta speak da language!

7
Learning Objectives
  • Be able to read and interpret a UML class diagram
  • Be able to write a simple class in VB.NET or
    C.Net
  • Be able to write a class that inherits from
    another class, changes some behavior and adds
    some behavior to the base class
  • Be able to define polymorphism
  • Be able to identify what encapsulation is and why
    it is important

8
Points of Interest
set
set
set
set
set
Inheritance
UML
Polymorphism
Encapsulation
9
UML and Class Diagrams
Class Diagram
Name
Member Variables nametype
Methods name(parameters the method uses) return
type
10
Basic Airplane Class
C.NET using System using System.Collections.Gene
ric using System.Text namespace
Objectville_Demo_CS public class Airplane
private int speed public
Airplane() // constructor
public virtual void setSpeed(int speed)
this.speed speed public
virtual int getSpeed() return
speed
VB.NET Public Class Airplane Private mSpeed
As Integer Sub New() End Sub Public
Sub SetSpeed(ByVal value As Integer)
mSpeed value End Sub Public Function
GetSpeed() As Integer Return mSpeed
End Function End Class
11
What doesnt the Class Diagram give you?
  • Variable scope public, private, friend, etc
  • Full-blown UML does
  • Not usually needed
  • Information about the constructor method for the
    class
  • Details of what each method does

12
Inheritance
  • Once class inherits behavior from another class
  • Code keywords
  • VB Inherits
  • C uses (colon) to indicate inheritance
  • Derived class, subclass
  • Base class, superclass (vb MyBase)

13
Inheritance
VB.NET Public Class Jet Inherits Airplane
Private Const MULTIPLIER 2 Public Sub
New() MyBase.New() End Sub
Public Overrides Sub SetSpeed(ByVal value As
Integer) MyBase.SetSpeed(value
MULTIPLIER) End Sub Public Sub
Accelerate() MyBase.SetSpeed(GetSpeed()
2) End Sub End Class
C.NET public class JetAirplane
private const int MULTIPLIER 2 public
Jet() base() public
override void setSpeed(int speed)
base.setSpeed(speed MULTIPLIER)
public void accelerate()
base.setSpeed(getSpeed() 2)

14
Base Class Modifications (.NET)
Public Class Airplane Private mSpeed As
Integer Sub New() End Sub Public
Overridable Sub SetSpeed( ByVal value As
Integer) mSpeed value End Sub
Public Overridable Function GetSpeed() As
Integer Return mSpeed End
Function End Class
public class Airplane private int
speed public Airplane() //
constructor public
virtual void setSpeed(int speed)
this.speed speed public
virtual int getSpeed()
return speed
15
Putting the classes to workStart with a biplane
static void Main(string args)
FlyTest1() public static
void FlyTest1() Airplane
biplane new Airplane()
biplane.setSpeed(212)
Console.WriteLine(biplane.getSpeed()) Console.Re
adLine()
Module Module1 Sub Main() FlyTest()
End Sub Public Sub FlyTest() Dim
biplane As New Airplane
biplane.SetSpeed(212) Console.WriteLine(
_ biplane.GetSpeed()) Console.Read()
End Sub End Module
16
Module Module1 Puzzle 1 (VB) Sub Main()
FlyTest() End Sub Public Sub
FlyTest() Dim biplane As New Airplane
biplane.SetSpeed(___)
Console.WriteLine(_________________) Dim
boeing As New Jet boeing.SetSpeed(___)
Console.WriteLine(_________________)
______ While _______
___________________
Console.WriteLine(________________)
If (________________ gt 5000) Then
________________(________________ 2)
Else _________________
End If _________ End While
Console.WriteLine(biplane.GetSpeed)
Console.Read() End Sub End Module
Code snippets
212 Dim x 0 boeing.GetSpeed biplane.GetSp
eed() biplane.SetSpeed boeing.GetSpeed
biplane.Accelerate() biplane.GetSpeed 422 x lt
5 x lt 4 boeing.SetSpeed x 0 x lt 3 x x 1
424 boeing.Accelerate() x-- x 1
Desired output
212 844 1688 6752 13504 27008 1696
17
static void Main(string args) // puzzle 1 C
FlyTest1()
public static void FlyTest1()
Airplane biplane new Airplane()
biplane.setSpeed(___)
Console.WriteLine(____________) Jet
boeing new Jet()
boeing.setSpeed(___)
Console.WriteLine(________________)
_________ while (________)
_________________
Console.WriteLine(_____________________)
if ( ______________ gt 5000)
__________________(__
____________ 2)
else
______________________
___________
Console.WriteLine(biplane.getSpeed())
Console.ReadLine()
Code Snippets
212 boeing.getSpeed() biplane.getSpeed() 422
x 0 int x 0 x lt 4 boeing.accelerate()
biplane.setSpeed x-- x 1 x lt
3 boeing.getSpeed() boeing.accelerate()
boeing.getSpeed() biplane.getSpeed() x 424
x lt 5
Desired output
212 844 1688 6752 13504 27008 1696
18
Class Exercise 1
  • Divide into 2 groups
  • C
  • VB
  • Divide into teams of 3-4
  • Get the proper puzzle
  • Place the code snippets into the blank lines in
    the code
  • You can use the same snippet more than once
  • There are some (trick/decoy) snippets that you
    wont need.
  • Goal create a class that will produce the
    desired output.

19
DEMO
  • Walkthru of solution

20
A toonce of Polymorphism
inherits from
Airplane plane new Airplane()
Airplane plane new Airplane() Airplane plane
new Jet() Airplane plane new Rocket()
21
Encapsulation Escapades
  • Hiding information from the rest of your
    application
  • Hide the details within the object use Public
    sparingly
  • Demo change the internal speed variable from
    private to public
  • Run FlyTest2 and FlyTest3

22
Ricks Guitar Shop ApplicationUML Class Diagrams
Guitar
Inventory
serialNumberstring price double
builderstring typestring backWoodstring
topWoodstring
Guitars List
addGuitar(string,double,string,string, string,str
ing,string) getGuitar(string)Guitar
search(Guitar)Guitar initializeInventory printIn
ventory()
getSerialNumber()string getPrice()double setPric
e()double getBuilder()double getModel()string g
etType()double getBackWood()string getTopWood()
string
23
Main Application
InvInventory gGuitar whatErinLikesGuitar
initializeInventory(Inventory)
24
Demo
  • Walkthru Ricks Guitar Shop Application

25
Problems
  • Search routine does not work
  • Should use constants or enums instead of strings
  • Search should return multiple guitars
  • Architecture could use some restructuring
  • What would you do first with Ricks app?

26
Assignment
  • If yourre new to object oriented programming,
    read Appendix ii Welcome to Objectville
  • Work through exercises in Chapter 1
  • Download Ricks App from class site
  • Modify it to
  • Fix the search routine
  • Use enums instead of strings

27
FINIS
Write a Comment
User Comments (0)
About PowerShow.com