Created
April 18, 2018 14:49
-
-
Save toksdotdev/9f8a857789871df458b9b82096fbb862 to your computer and use it in GitHub Desktop.
Using OOP to represent things related to sailing...
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 Vessel { | |
List<SeaFarer> SeaFarers; // this is private automatically to help promote data abstraction | |
// (data shouldn't be assessed publicly, | |
// instead use GetSeaFearer() in this class ) | |
public Vessel() { // this is constructor | |
this.SeaFarers = new List<SeaFarers>(); // initializes the seaferes in constructor | |
} | |
public Vessel(List<SeaFarer> seaFarer) { //this is constructor overloading | |
this.SeaFarers = seaFarer; // initializes the vessel with given data (this is called dependecy injection) | |
} | |
public List<SeaFarer> GetSeaFearers() { | |
return this.SeaFarers; | |
} | |
} | |
class SeaFarer { | |
// add properties of a seafarer here | |
//e.g. | |
string FirstName { get; set; } | |
string LastName { get; set; } | |
Rank Rank { get; set; } // is of type 'Rank` ===> take a look at the rank enum below | |
// (this is better than hardcording string to know which | |
// level a seafarer is) | |
} | |
enum Rank { | |
LevelOneOfficer, | |
LevelTwoOfficer, | |
SeniorOfficer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment