How to point to a child class during runtime but not compile time? [duplicate] - objective-c

This question already has answers here:
What exactly is a so called "Class Cluster" in Objective-C?
(5 answers)
Objective C - How can I create an interface?
(4 answers)
Closed 7 years ago.
Problem: Suppose I have a class (call it cA), which has a reference to a helper class (call it HelperBase). The Helper class can be extended for specific implementations (call those HelperA, HelperB, etc.). However, I don't want cA to have any knowledge of the specific implementations either HelperA, HelperB, etc; I just want cA to call whatever methods are in Helper. Is there a way to do that? Is there a term for this? I'm also not sure what the terminology is for this kind of design (if there is one).
Examples in objective-c would be greatly appreciated. Thanks!

Related

Extending class in external library [duplicate]

This question already has answers here:
How to implement multiple inheritance in delphi?
(10 answers)
What are the pros and cons of using interfaces in Delphi?
(9 answers)
Closed 2 years ago.
I need to use an external library which has a class hierarchy, TC1 base, TC2 which derives from TC1, TC3A and TC3B which derive from TC2. I need to extend each class of this hierarchy with some attributes and methods, which will obviously need to be inherited from the derived classes. I don't want to change the library code. I can't use class helpers because I also have attributes to add. And Delphi doesn't support multiple inheritance. The use of encapsulation instead of inheritance seems to me not applicable in this case. How can I solve the problem?

What is an Object and a Class in python? [duplicate]

This question already has answers here:
What is the difference between objects and classes in Python
(5 answers)
Closed 3 years ago.
I came across the following line:
Every list object that you create in Python is actually an instance of List class.
What does Class and Object actually mean?
Another similar post
I saw the above post but in that they explain the difference between object and class. But what exactly is a class if Object is an instance of class.
Edit:
What is an instance?
Think of classes as blueprints for objects. So for example, you will only have one car model blueprint, and that is your class. Every single model that is produced is an instance. Hope it helps.

Abstract Methods/Classes in Objective-C? [duplicate]

This question already has answers here:
Creating an abstract class in Objective-C
(21 answers)
Closed 7 years ago.
I've realized there's no abstract classes in Objective-C. Is there any way to achieve the same functionality in some other way (a class that can't be instantiated, or methods that MUST be overridden by their subclass)?
It depends exactly what you want. If you would just use the class as an interface with no implementation then using a protocol instead is best. If you need some base or default implementation then you either document that the class shouldn't be instantiate do directly (common nowadays I think) or you implement the class to throw exceptions if it is instantiated directly (uncommon nowadays). Also throw exceptions in any methods that should be implemented by a subclass and are called on the superclass.
Unless you're creating a framework that will be delivered to other developers it's generally not worth the effort to implement, just document.

How to specify fully qualified class name in Objective C? [duplicate]

This question already has answers here:
What is the best way to solve an Objective-C namespace collision?
(13 answers)
Closed 8 years ago.
However, I have not met with any issues yet, but sometimes it might happen when we are using two completely independent frameworks, which might have two classes of common name. So, to resolve compiler ambiguity, how to specify that this class refers to this framework and this belongs to that framework. Like in Java, we can specify fully qualified class name like java.pkg.Class.
I know that all the classes are preceded by some characters those might identify the framework (like NS, SK, MK, etc.), but it still can happen. Is there any mechanism that I am missing? I have never heard of fully qualified class name in Objective C.
Objective-C does not have namespaces for its classnames. The class name (e.g. NSString) is the fully-qualified class name; that's as qualified as it gets.
Obviously, this can lead to collisions. Some developers have filed bugs asking for namespaced classes in Objective-C, but as of this writing, nothing has been done in response to those requests.
So no, there is no mechanism that you're missing.

Difference between subclass and category? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Difference between inheritance and Categories in Objective-c
What’s the difference and use of categories and inheritance?
thanks for your reply,for example we have nsstring class if we want to add methods to that class there is no need to create category for that,just we can subclass it but why we are using categories?Please help on this
Category adds some extra functionality to specific class (for example NSString). You don't need to declare the Object with that specific class name. You only import that category and all the Object implicitly become instance of the category, all the implementation is now available to them.
Where when subclassing, (sometimes you intently need to override the existing behavior/methods or you can add extra functionality too.) you explicitly declare that Object with the type like
MyCustomString *string;
and then all the methods become visible.