Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //adapted from the book "Practical Object-Oriented Design in Ruby" by Sandi Metz
- namespace GetterSetterExample
- {
- public class Gear
- {
- private int chainring, cog, rim; //instance data fields
- private double tire;
- public Gear (int chainring, int cog, int rim, double tire) //constructor
- {
- this.chainring = chainring;
- this.cog = cog;
- this.rim = rim;
- this.tire = tire;
- }
- public int GetChainringSize () //accessor (aka getter) for chainring
- {
- return this.chainring;
- }
- public void SetChainringSize (int chainringSize) //mutator (aka setter) for chainring
- {
- this.chainring = chainringSize;
- }
- public int GetCogSize () //accessor/getter for cog
- {
- return this.cog;
- }
- public void SetCogSize (int cogSize) //mutator/setter for cog
- {
- this.cog = cogSize;
- }
- public int GetRimSize () //accessor/getter for rim
- {
- return this.rim;
- }
- public void SetRimSize (int rimSize) //mutator/setter for rim
- {
- this.rim = rimSize;
- }
- public double GetTireSize () //accessor/getter for tire
- {
- return this.tire;
- }
- public void SetTireSize (double tireSize) //mutator/setter for tire
- {
- this.tire = tireSize;
- }
- }
- }
Add Comment
Please, Sign In to add comment