Created
April 6, 2014 18:03
-
-
Save willmcneilly/10009496 to your computer and use it in GitHub Desktop.
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
## Example of an abstract class | |
## They should be treated as a protocol for their sub classes to implement | |
## They shouldn't be directly instantiated | |
class Session | |
def initialize(name, time) | |
@time = time | |
@name = name | |
end | |
def report | |
print "#{@time} minutes on #{@name} = #{calories} calories\n" | |
end | |
end | |
class RowingSession < Session | |
def calories | |
@time * 10 | |
end | |
end | |
class ClimbingSession < Session | |
def initialize(name, time, program, weight) | |
super(name, time) | |
@program = program | |
@weight = weight | |
end | |
def calories | |
@time * 10 | |
end | |
end | |
session_1 = RowingSession.new("Ronnie", 10) | |
session_1.report | |
session_2 = ClimbingSession.new("Billy", 5, "Hill Climbing", 70) | |
session_2.report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment