Câu hỏi phỏng vấn Objective-C
Câu hỏi

How to create an abstra...

Câu trả lời

In Objective-C, there is no direct equivalent to abstract classes as found in other object-oriented programming languages like Java or C#. However, you can achieve a similar concept by using protocols and class clusters.

Here's how you can create an abstract class-like structure in Objective-C:

Using Protocols

  1. Define a protocol that declares the methods and properties that the abstract class would have.
objc Copy
@protocol AbstractClass
- (void)abstractMethod;
@property (nonatomic, copy) NSString *abstractProperty;
@end
  1. Create a concrete subclass that conforms to the protocol and implements the required methods and properties.
objc Copy
@interface ConcreteClass : NSObject <AbstractClass>
@end

@implementation ConcreteClass
- (void)abstractMethod {
    // Implement the abstract method
}

@synthesize abstractProperty;
@end
  1. Other classes can then inherit from the concrete subclass and override or extend its functionality as needed.
objc Copy
@interface AnotherClass : ConcreteClass
- (v...
senior

senior

Gợi ý câu hỏi phỏng vấn

expert

What is Dynamic Dispatch and how does it work in Objective-C?

middle

What is the difference between NSDictionary and NSMutableDictionary ?

middle

What's the difference between the atomic and nonatomic attributes?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào