Comparing Functional and OO Approaches


Conceptual design problem: Design a system to draw geometric shapes and manipulate them.
 
 
Functional Object Oriented
Proc Rotate (shape)
   case (shape)
        triangle:
        square:
        circle:
   end case
end proc
 
Proc Draw (shape)
   case (shape)
        triangle:
        square:
        circle:
   end case
end proc
 
Proc Zoom (shape)
   case (shape)
        triangle:
        square:
        circle:
   end case
end proc
 
        
class Triangle
   method rotate()
   method draw()
   method zoom()
end class
 
class Square
   method rotate()
   method draw()
   method zoom()
end class
 
class Pentagon
   method rotate()
   method draw()
   method zoom()
end class
 


Diagram comparing "pure" functional and oo approaches will go here.


 
 
 

When to use

Functional Object Oriented
  • Requirements emphasize "what does it do"
  • Highly process oriented
  • Simple data
  • Transient data 
  • Complex rules or logic
  • real time systems
  • sequential architectures
  • Requirements emphasize "what data does it manage"
  • Highly data oriented
  • Complex or rich data domain
  • Resident data 
  • Simple rules
  • event driven architectures
Examples Examples
Classic sequential data processing 
E.g. weekly payroll 

Scientific/engineering (lots of computations on simple numerical data) 

Message routing 

Artificial Intelligence 

networking

databases of any kind 

word processor 

image manipulation 

Computer aided drafting 

Simulation / modeling 

inventory control 

role playing games

Examples that could be either
Automated Teller Machine 

Compiler 

Operating Systems 


Application to different levels of design

Functional and object-oriented approaches are complementary rather than opposing techniques and each may be applicable at different levels in the design.  Consider the software in a modern civilian airliner.

High Level Design (object oriented)

Middle Level Design (functional) Low Level Design (object oriented)

Which is easier?

Those who argue that OO is easier assert: It can be argued that functional design is easier than OOD:



Symptoms of poor design choice

Your OO design should probably be a functional design if: Your functional design should probably be an OO design if:

CPE 205 Home