Linear Recursive Structures(LRS)

6
08/24/22 B.Ramamurthy 1 Linear Recursive Structures(LRS) Based on paper by D.Nyguen

description

Linear Recursive Structures(LRS). Based on paper by D.Nyguen. Recursive Definition. List is an Empty list Or a NonEmptyList with a head Object and a tail which is a List. - PowerPoint PPT Presentation

Transcript of Linear Recursive Structures(LRS)

Page 1: Linear Recursive Structures(LRS)

04/19/23 B.Ramamurthy 1

Linear Recursive Structures(LRS)

Based on paper by D.Nyguen

Page 2: Linear Recursive Structures(LRS)

04/19/23 B.Ramamurthy 2

Recursive Definition

List is an Empty listOr a NonEmptyList with a head Object and a tail which is a List.Empty list is typically represented by “null” giving rise to the famous NullPointerException. In this paper, EmptyList is represented by a NullObject (Pattern).

Page 3: Linear Recursive Structures(LRS)

04/19/23 B.Ramamurthy 3

NonEmptyList

List:

tail

Object

head

List

tail

Object

head

tail

Object

head

List (can be empty)

List:

tail

Object

head

tail

Object

headList:

tail

Object

head

List

Page 4: Linear Recursive Structures(LRS)

04/19/23 B.Ramamurthy 4

State-pattern based approach

EmptyNonEmpty

Add an Object

Remove an Objectsingleton Represents all

Possible nonEmptystates

Add an ObjectRemoveAn object

Page 5: Linear Recursive Structures(LRS)

04/19/23 B.Ramamurthy 5

List operations (add, remove)

List operations depend on the state of the list.Define a class hierarchy for state and polymorphically delegate the operations to the different types of states.Using State pattern: an abstract class specifies operations that are state dependent. A concrete class is defined for each discrete/functionally distinguishable state.

Page 6: Linear Recursive Structures(LRS)

UML Class Diagram

IContainer<<interface>>

AListNode<<Abstract class>>

EmptyListNode<<state>>

NonEmptyListNode

Object head;List tail;

<<state>>

List<<Concrete class>>

knows aknows a