langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
43
Task/Break-OO-privacy/Objective-C/break-oo-privacy.m
Normal file
43
Task/Break-OO-privacy/Objective-C/break-oo-privacy.m
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface Example : NSObject {
|
||||
@private
|
||||
NSString *_name;
|
||||
}
|
||||
- (id)initWithName:(NSString *)name;
|
||||
@end
|
||||
|
||||
@implementation Example
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:@"Hello, I am %@", _name];
|
||||
}
|
||||
- (id)initWithName:(NSString *)name {
|
||||
if ((self = [super init])) {
|
||||
_name = [name copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void)dealloc {
|
||||
[_name release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
int main (int argc, const char * argv[]) {
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
Example *foo = [[Example alloc] initWithName:@"Eric"];
|
||||
|
||||
// get private field
|
||||
NSLog(@"%@", foo->_name);
|
||||
|
||||
// set private field
|
||||
[foo->_name release];
|
||||
foo->_name = [@"Edith" copy];
|
||||
NSLog(@"%@", foo);
|
||||
|
||||
[foo release];
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
6
Task/Break-OO-privacy/Perl-6/break-oo-privacy.pl6
Normal file
6
Task/Break-OO-privacy/Perl-6/break-oo-privacy.pl6
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class Foo {
|
||||
has $!shyguy = 42;
|
||||
}
|
||||
my Foo $foo .= new;
|
||||
|
||||
say $foo.^attributes.first('$!shyguy').get_value($foo);
|
||||
Loading…
Add table
Add a link
Reference in a new issue