Created
May 31, 2010 04:37
-
-
Save jonsterling/419539 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #import <Cocoa/Cocoa.h> | |
| @interface Conversion : NSObject | |
| @end | |
| @interface Conversion (Abstract) | |
| - (NSString *)firstUnitName; | |
| - (NSString *)secondUnitName; | |
| - (double)secondValueForFirstValue:(double)firstValue; | |
| - (double)firstValueForSecondValue:(double)secondValue; | |
| @end |
This file contains hidden or 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
| #import <Cocoa/Cocoa.h> | |
| @protocol Converting <NSObject> | |
| @required | |
| - (NSString *)firstUnitName; | |
| - (NSString *)secondUnitName; | |
| - (double)secondValueForFirstValue:(double)firstValue; | |
| - (double)firstValueForSecondValue:(double)secondValue; | |
| @end | |
| @interface TemperatureConversion : NSObject <Converting> | |
| @end | |
| @interface OtherConversion : NSObject <Converting> | |
| @end |
This file contains hidden or 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
| #import "Conversion.h" | |
| @implementation TemperatureConversion | |
| #pragma mark - | |
| #pragma mark Converting methods | |
| - (NSString *)firstUnitName { | |
| return @"Celsius"; | |
| } | |
| - (NSString *)secondUnitName { | |
| return @"Fahrenheit"; | |
| } | |
| - (double)secondValueForFirstValue:(double)celsius { | |
| return (1.8 * celsius + 32.0); | |
| } | |
| - (double)firstValueForSecondValue:(double)fahrenheit { | |
| return ((fahrenheit - 32.0) / 1.8); | |
| } | |
| @end | |
| @implementation OtherConversion | |
| #pragma mark - | |
| #pragma mark Converting methods | |
| - (NSString *)firstUnitName { | |
| return @"Foo"; | |
| } | |
| - (NSString *)secondUnitName { | |
| return @"Bar"; | |
| } | |
| - (double)secondValueForFirstValue:(double)foo { | |
| return foo; // TODO: actually convert to something | |
| } | |
| - (double)firstValueForSecondValue:(double)bar { | |
| return bar; // TODO: actually convert to something | |
| } | |
| @end |
This file contains hidden or 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
| #import "Conversion.h" | |
| @interface TemperatureConversion : Conversion | |
| @end |
This file contains hidden or 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
| #import "TemperatureConversion.h" | |
| @implementation TemperatureConversion | |
| - (NSString *)firstUnitName { | |
| return @"Celsius"; | |
| } | |
| - (NSString *)secondUnitName { | |
| return @"Fahrenheit"; | |
| } | |
| - (double)secondValueForFirstValue:(double)celsius { | |
| return (1.8 * celsius + 32.0); | |
| } | |
| - (double)firstValueForSecondValue:(double)fahrenheit { | |
| return ((fahrenheit - 32.0) / 1.8); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment