Object-Oriented Analysis and Design Introduction Tom Perkins.

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Object-Oriented Analysis & Design Chapter 1 NTPCUG Study Series.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
1 CS2200 Software Development Polymorphism II A. O’Riordan, 2008 K. Brown,
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
SOS OOP Fall 2001 Object Oriented Programming in Java Week 1 Read a design Design a small program Extract a design Run a VAJ program Change that program,
UML Class Diagram: class Rectangle
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
9/4/2015Abstract classes & Interface1 Object Oriented Design and Programming II Chapter 10 Abstract classes and Interfaces.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Writing Classes (Chapter 4)
1 INF160 IS Development Environments AUBG, COS dept Lecture 13 Title: Classes: Introduction & Review (Extract from Syllabus)
Java Classes Using Java Classes Introduction to UML.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming Pillars Introduction to Object- Oriented Programming.
Features of Object Oriented Programming:  A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.6 Access Modifiers,
Nothing Stays the Same Chapter 5 HeadFirst OOAD Tom Perkins - NTPCUG.
Outline Creating Subclasses Overriding Methods Class Hierarchies Visibility Designing for Inheritance Inheritance and GUIs The Timer Class Copyright ©
Chapter 8 Inheritance Part 1. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Inheritance Inheritance is a fundamental object-oriented design technique.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
WELCOME to III SEM Date: Class - ECE no of present : no of absent :
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
CS 2430 Day 9. Announcements Quiz 2.1 this Friday Program 2 due this Friday at 3pm (grace date Sunday at 10pm)
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Outline Class and Object-Oriented Programing –Encapsulation and inheritance Example –Commission Employee –Encapsulation and inheritance Strings and Formatting.
 A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined Data type and is Known as Reference.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
OOP Basics Classes & Methods (c) IDMS/SQL News
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Lecture 12 Inheritance.
Abstraction, Interface, Inheritance, Polymorphism, Override / Overload
Microsoft Visual Basic 2005: Reloaded Second Edition
Design Class Diagrams
Object-Orientated Programming
Week 8 Lecture -3 Inheritance and Polymorphism
UML Class Diagram: class Rectangle
CS360 Windows Programming
Creating and Using Classes
OOP’S Concepts in C#.Net
Inheritance, Polymorphism, and Interfaces. Oh My
Week 6 Object-Oriented Programming (2): Polymorphism
By Rajanikanth B OOP Concepts By Rajanikanth B
Classes & Objects A deeper Look Chapter 10 & 11
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
Presentation transcript:

Object-Oriented Analysis and Design Introduction Tom Perkins

Pages: 634 Pub Date: November 2006 Publisher: O'Reilly by Brett McLaughlin, Gary Pollice, David West Head First Object-Oriented Analysis and Design Print ISBN-13: Print ISBN-10:

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 Major problem: Getting you involved!

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 UML Inheritance set Polymorphism Encapsulation

UML and Class Diagrams Airplane speed: int getSpeed(): int setSpeed(int) Class Diagram Member Variables name:type Name Methods name(parameters the method uses): return type

Basic Airplane Class 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 C#.NET using System; using System.Collections.Generic; 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; }

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 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 Jet:Airplane { 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); }

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; }

Putting the classes to work Start with a biplane 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 static void Main(string[] args) { FlyTest1(); } public static void FlyTest1() { Airplane biplane = new Airplane(); biplane.setSpeed(212); Console.WriteLine(biplane.getSpeed()); Console.ReadLine(); }

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 (________________ > 5000) Then ________________(________________ * 2) Else _________________ End If _________ End While Console.WriteLine(biplane.GetSpeed) Console.Read() End Sub End Module 212 Dim x = 0 boeing.GetSpeed biplane.GetSpeed() biplane.SetSpeed boeing.GetSpeed biplane.Accelerate() biplane.GetSpeed 422 x < 5 x < 4 boeing.SetSpeed x = 0 x < 3 x = x boeing.Accelerate() x-- x = Code snippets: Desired output:

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 ( ______________ > 5000) { __________________(______________ * 2); } else { ______________________; } ___________; } Console.WriteLine(biplane.getSpeed()); Console.ReadLine(); } 212 boeing.getSpeed() biplane.getSpeed() 422 x = 0 int x = 0; x < 4 boeing.accelerate() biplane.setSpeed x-- x = 1 x < 3 boeing.getSpeed() boeing.accelerate() boeing.getSpeed() biplane.getSpeed() x x < 5 Code Snippets: Desired output:

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 won’t need. Goal: create a class that will produce the desired output.

DEMO “Walkthru” of solution

A “toonce” of Polymorphism Airplane speed: int getSpeed(): int setSpeed(int) Jet MULTIPLIER: int accelerate() “inherits from” 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 serialNumber:string price: double builder:string type:string backWood:string topWood:string getSerialNumber():string getPrice():double setPrice():double getBuilder():double getModel():string getType():double getBackWood():string getTopWood():string Inventory Guitars: List addGuitar(string,double,string,string, string,string,string) getGuitar(string):Guitar search(Guitar):Guitar initializeInventory: printInventory()

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

FINIS