Linear Recursive Structures(LRS)
-
Upload
jacqueline-simon -
Category
Documents
-
view
39 -
download
0
description
Transcript of Linear Recursive Structures(LRS)
![Page 1: Linear Recursive Structures(LRS)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/1.jpg)
04/19/23 B.Ramamurthy 1
Linear Recursive Structures(LRS)
Based on paper by D.Nyguen
![Page 2: Linear Recursive Structures(LRS)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/2.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/3.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/4.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/5.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022082414/56812d64550346895d927374/html5/thumbnails/6.jpg)
UML Class Diagram
IContainer<<interface>>
AListNode<<Abstract class>>
EmptyListNode<<state>>
NonEmptyListNode
Object head;List tail;
<<state>>
List<<Concrete class>>
knows aknows a