0% found this document useful (0 votes)
124 views25 pages

Object-Oriented Analysis and Design: Tom Perkins

The document provides an introduction and overview of the Head First Object-Oriented Analysis and Design book. It describes the book's chapters, obstacles in learning OOAD, and approach to teaching the concepts through examples, exercises, and hands-on activities. The document also includes code snippets demonstrating basic class concepts like inheritance and polymorphism in C# and VB.NET.

Uploaded by

Rupesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views25 pages

Object-Oriented Analysis and Design: Tom Perkins

The document provides an introduction and overview of the Head First Object-Oriented Analysis and Design book. It describes the book's chapters, obstacles in learning OOAD, and approach to teaching the concepts through examples, exercises, and hands-on activities. The document also includes code snippets demonstrating basic class concepts like inheritance and polymorphism in C# and VB.NET.

Uploaded by

Rupesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Object-Oriented Analysis and

Design
Introduction
Tom Perkins
• 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
Head First Chapters
1. Great Software Begins Here
2. Gathering Requirements
3. Requirements Change
4. Analysis
5. Handling Change
1. Small Changes lead to Big Problems
2. Incorporating Flexibility
6. Software Architecture
7. Bringing Order to Chaos
8. Design Principles
9. Iterating and Testing
10. An OOAD Software Process
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
Approach
• Stick close to the book
• As much code as possible
• Walkthru’s
• Get your hands dirty, become involved
• Do the book exercises
• Work with someone where possible
• Participate in class discussions
• Team Learning Experiments
Welcome to Objectville

“Foist, youse gotta speak da


language!”
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
Points of Interest
set

set
set
set
set

Inheritance

UML Polymorphism

Encapsulation
UML and Class Diagrams
Class Diagram

Airplane Name
speed: int Member Variables
getSpeed(): int name:type
setSpeed(int)

Methods
name(parameters the method uses): return type
Basic Airplane Class
C#.NET
VB.NET
using System;
Public Class Airplane
using System.Collections.Generic;
Private mSpeed As Integer
using System.Text;
Sub New()
namespace Objectville_Demo_CS
End Sub
{
public class Airplane
Public Sub SetSpeed(ByVal value As
{
Integer)
private int speed;
mSpeed = value
public Airplane(){ // constructor
End Sub
}
Public Function GetSpeed() As Integer
public virtual void setSpeed(int speed) {
Return mSpeed
this.speed = speed;
End Function
}
End Class
public virtual int getSpeed() {
return speed;
}
}
What doesn’t 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
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)
Inheritance
VB.NET C#.NET
Public Class Jet public class Jet:Airplane
Inherits Airplane {
private const int MULTIPLIER = 2;
Private Const MULTIPLIER = 2
Public Sub New() public Jet() : base()
MyBase.New() {
End Sub }
public override void setSpeed(int
Public Overrides Sub SetSpeed(ByVal speed)
value As Integer) {
MyBase.SetSpeed(value * base.setSpeed(speed *
MULTIPLIER) MULTIPLIER);
End Sub }
Public Sub Accelerate() public void accelerate()
MyBase.SetSpeed(GetSpeed() * 2) {
End Sub base.setSpeed(getSpeed() * 2);
End Class }
}
Base Class Modifications
Public Class Airplane
(.NET)
public class Airplane
Private mSpeed As Integer {
private int speed;
Sub New() public Airplane() // constructor
End Sub {
}
Public Overridable Sub public virtual void setSpeed(int speed)
SetSpeed( ByVal value As Integer) {
mSpeed = value this.speed = speed;
End Sub }
Public Overridable Function GetSpeed() public virtual int getSpeed()
As Integer {
Return mSpeed return speed;
End Function }
End Class }
Putting the classes to work
Start with a biplane
Module Module1 static void Main(string[] args)
{
Sub Main() FlyTest1();
FlyTest() }
End Sub public static void FlyTest1()
Public Sub FlyTest() {
Dim biplane As New Airplane Airplane biplane = new Airplane();
biplane.SetSpeed(212) biplane.setSpeed(212);
Console.WriteLine( _ Console.WriteLine(biplane.getSpeed());
biplane.GetSpeed()) Console.ReadLine();
Console.Read() }
End Sub

End Module
Module Module1 ‘Puzzle 1 (VB)
Code snippets:
Sub Main()
FlyTest()
212 Dim x = 0 boeing.GetSpeed
End Sub
Public Sub FlyTest() biplane.GetSpeed() biplane.SetSpeed
Dim biplane As New Airplane boeing.GetSpeed biplane.Accelerate()
biplane.SetSpeed(___) biplane.GetSpeed 422 x < 5
Console.WriteLine(_________________)
x < 4 boeing.SetSpeed x = 0 x < 3
Dim boeing As New Jet x = x + 1 424
boeing.SetSpeed(___) boeing.Accelerate() x-- x = 1
Console.WriteLine(_________________)
______
While _______ Desired output:
___________________
Console.WriteLine(________________) 212
If (________________ > 5000) Then
________________(________________ * 2)
844
Else
_________________
1688
End If
_________
6752
End While
13504
Console.WriteLine(biplane.GetSpeed)
Console.Read() 27008
End Sub
1696
End Module
static void Main(string[] args) // puzzle 1 C#
{
FlyTest1();
} Code Snippets:
public static void FlyTest1()
{
Airplane biplane = new Airplane();
212 boeing.getSpeed()
biplane.setSpeed(___); biplane.getSpeed() 422 x = 0
Console.WriteLine(____________); int x = 0; x < 4 boeing.accelerate()
Jet boeing = new Jet(); biplane.setSpeed x-- x = 1 x < 3
boeing.setSpeed(___);
Console.WriteLine(________________); boeing.getSpeed() boeing.accelerate()
_________; boeing.getSpeed() biplane.getSpeed()
while (________) x++ 424 x<5
{
_________________;
Console.WriteLine(_____________________);
Desired output:
if ( ______________ > 5000) 212
{
__________________(______________ * 2); 844
}
else 1688
{
______________________; 6752
}
___________; 13504
}
Console.WriteLine(biplane.getSpeed()); 27008
Console.ReadLine();
} 1696
DEMO

“Walkthru” of solution
A “toonce” of Polymorphism
Airplane Jet
speed: int MULTIPLIER: int
getSpeed(): int accelerate()
setSpeed(int)
“inherits from”

Airplane plane = new Airplane(); Airplane plane = new Airplane();


Airplane plane = new Jet();
Airplane plane = new Rocket();
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
Rick’s Guitar Shop Application
UML Class Diagrams
Guitar Inventory
serialNumber:string Guitars: List
price: double
builder:string addGuitar(string,double,string,string,
type:string string,string,string)
backWood:string getGuitar(string):Guitar
topWood:string search(Guitar):Guitar
initializeInventory:
getSerialNumber():string printInventory()
getPrice():double
setPrice():double
getBuilder():double
getModel():string
getType():double
getBackWood():string
getTopWood():string
Main Application
Inv:Inventory
g:Guitar
whatErinLikes:Guitar
initializeInventory(Inventory)
Demo

Walkthru Rick’s Guitar Shop


Application
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 Rick’s app?


Assignment
• If your’re new to object oriented
programming, read Appendix ii: Welcome
to Objectville
• Work through exercises in Chapter 1
• Download Rick’s App from class site
• Modify it to:
– Fix the search routine
– Use enums instead of strings

You might also like