20
A Brief Introduction to A Brief Introduction to Object-Orientation Object-Orientation (The Light Version) (The Light Version)

A Brief Introduction to Object-Orientation (The Light Version)

Embed Size (px)

DESCRIPTION

A quick overview of object-oriented concepts and terminology.

Citation preview

Page 1: A Brief Introduction to Object-Orientation (The Light Version)

A Brief Introduction to A Brief Introduction to Object-OrientationObject-Orientation

(The Light Version)(The Light Version)

Page 2: A Brief Introduction to Object-Orientation (The Light Version)

The Path to Object OrientationThe Path to Object Orientation

Before we can begin object-oriented Before we can begin object-oriented programming, we must learn how to programming, we must learn how to write programs using structured write programs using structured (procedural) techniques.(procedural) techniques.

Why? Because objects are made Why? Because objects are made partly of the same functions and partly of the same functions and control structures used in procedural control structures used in procedural programs.programs.

Page 3: A Brief Introduction to Object-Orientation (The Light Version)

Procedural vs. Object-OrientedProcedural vs. Object-Oriented

ProceduralProcedural Based on actionsBased on actions ““What happens, What happens,

and in what and in what order?”order?”

Functions are the Functions are the basic units.basic units.

Design process Design process focuses on verbs.focuses on verbs.

Object-OrientedObject-Oriented Based on objectsBased on objects ““What things are What things are

we dealing with?”we dealing with?”

Objects are the Objects are the basic units.basic units.

Design process Design process focuses on nouns.focuses on nouns.

Page 4: A Brief Introduction to Object-Orientation (The Light Version)

Why Object-Orientation?Why Object-Orientation?

More realistic relationships between More realistic relationships between software objects.software objects.

Significantly reduced complexity.Significantly reduced complexity. UltimateUltimate forms of reuse – reusing forms of reuse – reusing

program code program code andand reusing design reusing design solutions.solutions.

And much, much more…And much, much more…

Page 5: A Brief Introduction to Object-Orientation (The Light Version)

What is an Object?What is an Object?

A single conceptual entityA single conceptual entity A "thing" with attributes and A "thing" with attributes and

behaviorsbehaviors Essentially, program code packaged Essentially, program code packaged

into an isolated unit with "interfaces" into an isolated unit with "interfaces" for other objects to usefor other objects to use

Page 6: A Brief Introduction to Object-Orientation (The Light Version)

Some Object TerminologySome Object Terminology ObjectsObjects – Just look around you. – Just look around you. AbstractionAbstraction – Our ability to consider – Our ability to consider

things from a different perspective.things from a different perspective. ClassesClasses – We can classify things and – We can classify things and

decide if they are alike or different.decide if they are alike or different. PolymorphismPolymorphism – Different things can – Different things can

respond differently to the same command.respond differently to the same command. AttributesAttributes – Features that describe. – Features that describe. BehaviorsBehaviors – Activities, capabilities. – Activities, capabilities.

Page 7: A Brief Introduction to Object-Orientation (The Light Version)

EncapsulationEncapsulation

EncapsulationEncapsulation means that we can means that we can store our data along with the code store our data along with the code that operates on it, plus we can hide that operates on it, plus we can hide the ugly, complex details inside of a the ugly, complex details inside of a class. (This is called class. (This is called information information hidinghiding.).)

Page 8: A Brief Introduction to Object-Orientation (The Light Version)

Relationships Between ClassesRelationships Between Classes

InheritanceInheritance specifies that objects specifies that objects can be types of other objects. (A can be types of other objects. (A dog dog is ais a type of animal.) type of animal.)

Classes can contain objects of other Classes can contain objects of other classes through classes through compositioncomposition relationships. (A dog relationships. (A dog has ahas a nose.) nose.)

Page 9: A Brief Introduction to Object-Orientation (The Light Version)

A Class HierarchyA Class Hierarchy

Vehicle

LandVehicle Watercraft Aircraft

Automobile Bicycle FixedWingCraft RotaryWingCraft

Car Truck Van SUVJet PropDrivenPlane

FighterJet PassengerJet

Page 10: A Brief Introduction to Object-Orientation (The Light Version)

Object-Based vs. Object Object-Based vs. Object OrientedOriented

““Object-based” means you can Object-based” means you can create objects, but not define create objects, but not define inheritance relationships between inheritance relationships between them.them.

““Object-Oriented” means that all Object-Oriented” means that all relationships may exist, including relationships may exist, including inheritance.inheritance.

Page 11: A Brief Introduction to Object-Orientation (The Light Version)

Where Do Objects Come From?Where Do Objects Come From?

Objects are first Objects are first defineddefined with a class, with a class, then then instantiatedinstantiated..

A A classclass defines the attributes and defines the attributes and behaviors of an objectbehaviors of an object

InstantiationInstantiation is the creation of an is the creation of an object using a class definitionobject using a class definition

Page 12: A Brief Introduction to Object-Orientation (The Light Version)

Anatomy of an ObjectAnatomy of an Object

Objects encapsulate data along with Objects encapsulate data along with the operations on that data.the operations on that data.

1.1. Attributes (Properties)Attributes (Properties) Things that describe the objectThings that describe the object To us, this is data; variablesTo us, this is data; variables

1.1. Methods (Functions)Methods (Functions) Behaviors of the object; the various Behaviors of the object; the various

activities it can performactivities it can perform

Page 13: A Brief Introduction to Object-Orientation (The Light Version)

Object-Oriented Analysis and Object-Oriented Analysis and Design: An OverviewDesign: An Overview

1.1. Identify the Identify the nounsnouns in the problem in the problem statement. Determine what must statement. Determine what must be known about them and the be known about them and the actions they must perform.actions they must perform.

2.2. Diagram relationships between Diagram relationships between them. Write pseudocode for their them. Write pseudocode for their actions.actions.

3.3. Finally, write the code.Finally, write the code.

Page 14: A Brief Introduction to Object-Orientation (The Light Version)

Object-Oriented Analysis (OOA)Object-Oriented Analysis (OOA)

Gather requirements from the Gather requirements from the intended users.intended users.

Compile a list of these requirements.Compile a list of these requirements. Write a clear description of the Write a clear description of the

problem to be solved. This is the problem to be solved. This is the problem statementproblem statement..

Optionally, create use case Optionally, create use case diagrams.diagrams.

Page 15: A Brief Introduction to Object-Orientation (The Light Version)

Identifying ClassesIdentifying Classes

List all the nounsList all the nouns Pick out the nouns that store Pick out the nouns that store

important information or perform important information or perform necessary dutiesnecessary duties

Categorize them into classesCategorize them into classes Design each class as independently Design each class as independently

as possible; they will become the as possible; they will become the individual building blocksindividual building blocks

Page 16: A Brief Introduction to Object-Orientation (The Light Version)

Identifying AttributesIdentifying Attributes

Look for descriptive words in the Look for descriptive words in the problem statementproblem statement

Create a meaningful attribute name Create a meaningful attribute name for eachfor each

Decide which class the attribute Decide which class the attribute belongs tobelongs to

Create additional attributes for any Create additional attributes for any data that needs to be maintaineddata that needs to be maintained

Page 17: A Brief Introduction to Object-Orientation (The Light Version)

Real-World AttributesReal-World Attributes

PeoplePeople• HeightHeight• WeightWeight

CarsCars• SpeedSpeed• Odometer readingOdometer reading• Current fuel levelCurrent fuel level• Current gearCurrent gear

RadiosRadios• Current station Current station

settingsetting• Volume levelVolume level• AM or FMAM or FM

ComputersComputers• BrandBrand• Screen typeScreen type• Memory sizeMemory size• Drive capacityDrive capacity

Page 18: A Brief Introduction to Object-Orientation (The Light Version)

Stepwise RefinementStepwise Refinement

Not all classes will have attributes at Not all classes will have attributes at first. They can be added as the first. They can be added as the system is designed.system is designed.

Furthermore, some attributes you Furthermore, some attributes you may add in this phase will not be may add in this phase will not be needed in the final product.needed in the final product.

Designs don’t have to be perfect Designs don’t have to be perfect in order to be useful!in order to be useful!

Page 19: A Brief Introduction to Object-Orientation (The Light Version)

The Parts of an AttributeThe Parts of an Attribute

Like regular variables, attributes Like regular variables, attributes have:have:• NameName• TypeType• ValueValue

Name and type are defined in the Name and type are defined in the beginningbeginning

Value can be set in the beginning or Value can be set in the beginning or laterlater

Page 20: A Brief Introduction to Object-Orientation (The Light Version)

Your Future As An Object-Your Future As An Object-Oriented Software DeveloperOriented Software Developer

Software ArchitectureSoftware Architecture UMLUML Design PatternsDesign Patterns Agile Development ProcessesAgile Development Processes Many, MANY OO languages and toolsMany, MANY OO languages and tools