-
-
Save cameronpresley/45dfdcb1bf4edf1d61539adb8a8170bf to your computer and use it in GitHub Desktop.
Mars Rover - Modeling Concepts
This file contains 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 enum Command | |
{ | |
MoveForward, MoveBackward, | |
TurnLeft, TurnRight, | |
Quit | |
} |
This file contains 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
type Command = MoveForward | MoveBackward | |
| TurnLeft | TurnRight | Quit |
This file contains 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 Address | |
{ | |
public int HouseNumber {get; set;} | |
public string StreetName {get; set;} | |
public State State {get; set;} | |
} |
This file contains 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
type Address = { | |
houseNumber:int, | |
streetName:string, | |
state:State | |
} |
This file contains 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 Coordinate | |
{ | |
public int X {get; set;} | |
public int Y {get; set;} | |
} |
This file contains 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
type Coordinate = {x:int; y:int} |
This file contains 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 enum Direction | |
{ | |
North, South, East, West | |
} |
This file contains 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
type Direction = North | East | South | West |
This file contains 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 enum State | |
{ | |
Alabama, Alaska, California, Delaware, | |
Florida, Georgia, Tennessee, Wyoming | |
} | |
public enum Suit | |
{ | |
Hearts, Clubs, Spades, Diamonds | |
} | |
public enum Months | |
{ | |
January, February, March, April, May, June, | |
July, August, September, October, November, December | |
} |
This file contains 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
type State = Alabama | Alaska | California | |
| Delaware | Florida | Georgia | |
| Tennesee | Wyoming |
This file contains 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
// If the value isn't a major component of the design, we can use a primitive type | |
int houseNumber; | |
// However, if the type is a major concept to the domain at hand, | |
// it makes sense to lift it to its own type | |
public class HouseNumber | |
{ | |
public int Value {get;} | |
public StreetNumber(int input) | |
{ | |
// validation logic | |
Value = input; | |
} | |
} | |
// The difference between the two approaches is that in the first case, this would work | |
int houseNumber = 400; | |
Math.Sqrt(houseNumber); | |
// But this wouldn't | |
var houseNumber = new HouseNumber(400); | |
Math.Sqrt(houseNumber); // fails to compile with "cannot convert from HouseNumber to double" |
This file contains 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
// If the value isn't a major component of the design, we can use a primitive type | |
let houseNumber:int; | |
// However, if the type is a major concept to the domain at hand, | |
// it makes sense to lift it to its own type (single case sum type) | |
type HouseNumber = HouseNumber of int | |
// The difference between the two approaches is that in the first case, this would work | |
let houseNumber = 400; | |
Math.Sqrt(houseNumber); | |
// But this wouldn't | |
let houseNumber = HouseNumber 400 | |
Math.Sqrt(houseNumber); // fails to compile with | |
// "This expression was expected to have type 'float' but here has type 'HouseNumber'" |
This file contains 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 Rover | |
{ | |
public Direction Orientation {get; set;} | |
public Coordinate Location {get; set;} | |
} |
This file contains 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
type Rover = { | |
orientation:Direction; | |
location:Coordinate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment