Last active
August 29, 2015 14:21
-
-
Save mastoj/e0dc78af9462a796acb9 to your computer and use it in GitHub Desktop.
Helps clearify things for this blog post: http://blog.bjartwolf.com/?p=4522
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
private readonly PersonState _state; | |
public Person(string name) | |
{ | |
_state = new PersonState(name); | |
} | |
public string GetName() | |
{ | |
return _state.Name; | |
} | |
public void ChangeName(string name) | |
{ | |
_state.Name = name; | |
} | |
private class PersonState | |
{ | |
public string Name { get; set; } | |
internal PersonState(string name) | |
{ | |
Name = name; | |
} | |
} | |
} | |
public class SomeThing | |
{ | |
public SomeThing() | |
{ | |
var x = new Person("Tomas"); | |
x.ChangeName("John"); | |
x.GetName(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Person = | |
type PersonState = private {name: string} | |
let create name = {name = name} | |
let getName state = state.name | |
let changeName name state = {state with name = name} | |
module Something = | |
open Person | |
let x = create "Tomas" | |
let y = x |> changeName "John" | |
let name = x |> getName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment