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 sending a message to nil means and how is it actually useful?

junior

What are blocks and how are they used?

senior

Why delegate is never retained?

Bình luận

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

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