Linear Recursive Data Structures Using ObjectOriented State Patterns - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Linear Recursive Data Structures Using ObjectOriented State Patterns

Description:

A Process through which superfluous details are systematically removed to reveal ... The Yin-Yang of Rectangles. Non Square. Square. Just how smart is a null node? ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 19
Provided by: steph172
Category:

less

Transcript and Presenter's Notes

Title: Linear Recursive Data Structures Using ObjectOriented State Patterns


1
Linear Recursive Data Structures Using
Object-Oriented State Patterns
  • or
  • Just how smart is a a null node anyway?

Stephen Wong, Oberlin College Dung Zung Nguyen,
Pepperdine University
2
Squares and Rectangles
  • Is a square a rectangle?
  • YesNo..Aieeeeeee!..
  • Two states of a rectangle?
  • Square
  • Non-Square

3
Recursive Definition of Linear Structures (Lists)
  • What is a LRS/list?
  • Two different types of LRSs
  • Empty
  • Non-Empty
  • Are the different types really the same?
  • Do you care?

4
Abstraction, a la Matisse
A Process through which superfluous details are
systematically removed to reveal the intrinsic
nature.
5
Recursive Definition of Linear Structures (Lists)
  • Abstract the structure!
  • For non-empty LRS
  • The data or First ( car)
  • The tail or Rest ( cdr), which is a LRS!
  • Abstract the behavior!
  • Separate the Invariant vs. Variant Behaviors
  • Get/Set methods for First and Rest.
  • State change methods (insertAsFirst, remove).
  • Other variant methods (queries, display, etc.)

6
The Power of Abstraction
  • Closest match between the reality of the
    situation and the software model.
  • Helps control and understand the complexity of a
    large system.
  • Creates robust, flexible and extensible code

7
State Diagram for a LRS
Empty List
Non-Empty List
AddItem
Remove Item
8
Rectangles and Lists?
  • Systems that change states dynamically.
  • Dynamic reclassification an object that behaves
    differently in different states as if it changes
    classes.
  • Design solution for languages that do not support
    this feature?

9
State Design Pattern
  • Encapsulate states as concrete classes.
  • Abstract them into an abstract class.
  • The system contains a reference to an abstract
    state class, which can be an of the concrete
    state classes dynamically.

How can we express this?
10
Unified Modeling Language
  • A way of focusing on the the structure of a
    system of objects.
  • Separates the interfaces from the
    implementations.
  • Shows classes, methods, and attributes.
  • Shows inheritance relationships and associations.

11
UML Diagram of the State Design Pattern
12
Invariant LRS Behaviors
  • Get/Set First
  • Get/Set Rest
  • InsertAsFirst
  • RemoveFirst

13
Intelligent States
  • The LRSs user doesnt necessarily care which
    state the LRS is in.
  • Each case determines its own course.
  • No conditional statements are necessary.
  • The null (empty) case can handle itself.
  • Emptiness has behavior and intelligence!

14
Object-Oriented Data Structures
Represent the pure behavior of the structure of
the data, independent of the data itself.
15
Whats wrong with this picture?
  • Why are the variant behaviors coded together with
    the invariant behaviors?
  • But arent the variant behaviors still the domain
    of the data structure object?
  • But who can predict future behavioral needs?
  • We need extensibility.
  • We need to de-couple the variant algorithms from
    the data structure.

Stay tuned!!
16
Venn Diagram of Rectangles?
Non Square
Square
Nahhh.
17
The Yin-Yang of Rectangles
Square
Non Square
18
Just how smart is a null node?
Just because you dont have any information
doesnt mean you arent smart enough to take
care of yourself!
Write a Comment
User Comments (0)
About PowerShow.com