Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //from the book "Practical Object-Oriented Design in Ruby" by Sandi Metz
- namespace POODR_Example
- {
- public class Gear
- {
- private int chainring, cog, rim; //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 GetGearInches () //public accessor method
- {
- return GetRatio() * new Wheel(rim, tire).GetDiameter();
- }
- private int GetRatio () //private helper method
- {
- return chainring / cog;
- }
- }
- public class Wheel
- {
- private int rim; //data fields
- private double tire;
- public Wheel (int rim, double tire) //constructor
- {
- this.rim = rim;
- this.tire = tire;
- }
- public int GetDiameter () //public accessor method
- {
- return rim * (int)(tire * 2);
- }
- }
- }
Add Comment
Please, Sign In to add comment