8. Primitive Types
These are struct types in C#
Represents a single value
Examples: bool, char, float, int
9. Composite Types
In C#, everything else is a form of a composite type
Typical examples
Array
Record
Tuple
Struct (not the C# struct)
Plain Old Data Structure
Union
Tagged Union – Union that tracks current type
Object – Data + Behavior
10. Abstract Types
These are abstract composite types, structural implementations vary
Examples
Dictionary
List
Set
Tree
Graph
11. Graph
Composed of nodes (or vertices) and edges
Node
1 2 Edge
3 4 5
12. Digraph
Apply a direction
Removing direction is called the “underlying graph.”
1 2
3 4 5
13. Weighted Graph
Edge contains value
Useful for determining optimal routes between destinations
2.2
1 2
3.7 6.0
1.5 0.5
3 4 5
14. Multigraph
More than one edge allowed between nodes
1 2
3 4 5
15. Hypergraph
Edges can connect more than two nodes
I view hyper-edges as categories
1 2
3 4 5
16. Tree
A graph with parent-child relationships
No node can be the child of more than one node
1 2
3 4 5
6
17. List
A graph where each node is connected to 1 or 2 nodes
Explicitly has an order
1 2 3 4 5
18. Set Comparisons
List – Ordered, allows duplicates, single type
Tuple – Ordered, allows duplicates, multiple types
Set – Unordered, no duplicates, single type
22. Structural Patterns
Difference with Data Structures
Focus is to use structure to enable behavior
There is potential overlap with abstract types
Examples
Adapter
Composite
Decorator
Façade
Flyweight
23. Behavioral Patterns
Difference with Structural
Behavior isn’t necessarily driven by the structure
Examples
Chain of Responsibility
Command
Iterator
Observer
Specification
Visitor
24. Iterator
an object that provides a standard way to examine all element of
any collection.
Has a uniform interface for traversing many data structure without
exposing their implementations.
Supports concurrent iteration and element removal.
No need to know the internal structure of collection.
26. Observer
An object, called the subject, maintains a list of its dependents
Dependents are known as observers
Observers are notified when subject’s state changes
30. Specification
Separates business rules from business objects
Represents object-oriented predicates and predicate combinators
Predicate – conditionals that can be passed
The pattern uses “IsSpecifiedBy” to indicate whether the predicate is
successful
34. Example Query
from x in object1
from y in object2
select x + y; What can you tell me
about
object1?
35. LINQ to Objects
This is LINQ over the iterator pattern
The iterator pattern in C# is implemented with IEnumerable
Much more declarative than foreach loops
Lazy Execution
36. LINQ to SQL/EF/Etc
Uses visitor pattern
Lambdas represent Expressions rather than functions
Visitor translates expressions into another language
37. Reactive
LINQ to observer pattern
Items are pushed instead of pulled
Great for asynchronous programming
Is now open source
43. What Does LINQ to Functions Mean
Applying LINQ to new forms require reimagining the DSL
In the case of functions, LINQ combines functions
Each LINQ method is a functional combinator
44. “ a combinator is a function
which builds program
fragments from program
fragments…
JOHN HUGHES
”
54. Explanation
Predicates are functions, but they combine differently than other
functions
Therefore, it makes more sense to wrap them so specific
combinators can be applied