Protege Subclass A controls Subclass B and Subclass C - ontology

EVChargerDeviceFunction (A) is subclass of Function.
CancelSetpointCommandand (B) and SetPowerSetpointCommand (C) are subclasses of Command.
hasCommand objectProperty domains Function and ranges Command.
How do I let Protege know that the function subclass (A) controls the other two command subclasses (B) and (C)?
Is it correct to say a new "hasCommand" is subclass of "hasCommand",it domains (A) and ranges (B) and (C)?

Related

UIView & Subview Delegates

I just wanted to clear up some confusion that I have with the delegate pattern that should be constructed when there are multiple UIViews and Subviews of these views. To make it clear, let's define some variables.
Let us define these objects as:
ViewController A
UIView B
Subview C
Now, I understand how the delegation pattern works (I think), although I am unsure how to implement this pattern in nested UIViews. Some questions I have are:
Should C contain a delegate implemented by it's super view (B)?
And if yes, should B then pass this information to it's delegate ViewController (A)?
Here's a scenario, let's say C has a UITextView, this text view's height is determined by a string fetched from an API service. B does not have access to the API since this job should be done via the ViewController (A).
Should C then contain a delegate which points to:
The ViewController's (A) delegate implementation?
The UIView's (B) delegate implementation?
Other?
If the answer is ( 2 ) then should B then call the ViewController (A) and pass this information via a chain of events?
Here's a small visual:
A <IBDelegate> <--- B <ICDelegate> <--- C calls Delegate.OnApiComplete(float height);
What is the "Delegate" in this case? (ICDelegate or IBDelegate). And what are the chain of events?
I am just trying to avoid any unnecessary logic to seep into the UIView's when the responsibility should be on the controller.
I understand that you can solve most of these scenario's with a shared object between UIViews, but when it comes to network services, these values need to be retrieved via some sort of callback.
I further clarification is needed, let me know. Any help is greatly appreciated.
So, you have situation like:
ViewController A --> View B --> View C
I would try to ensure that my ViewController A takes decisions both for View B & View C like this:
Create a protocol ViewDelegate and keep both View B and View C
delegate methods in it.
Create a property #property (nonatomic, weak) id <ViewDelegate> delegate; in View B.
Create a property #property (nonatomic, weak) id <ViewDelegate>
delegate; in View C.
From ViewController A while instantiating View B set self as delegate. Like viewBObj.delegate = self.
From View B while instantiating View C set self.delegate as delegate. Like viewBObj.delegate = self.delegate.
This would make ViewController A responding to both View B and View C delegate events.
Delegate are function pointers. Using it, one can call another class' function easily.
To create delegate, common procedure is to, first create protocol and add relevant methods in it (in the class you want to initiate delegate method). This methods can be implemented by class that adopts protocol.
You also need to create generic property of protocol type called delegate property. This will be assigned to instance of class that conforms to protocol.
In your case, class B and class C has some protocols defined in it. Here, B conforms class C's protocol and class A conforms class B's protocol.
Now, class B has object defined of class c in it. In class B, here we need to assign class C's delegate to instance of B(self). (now in class c, delegate property contains instance of B and one can easily call protocol method implemented in class B from class C).
The same scenario happen in class A and B where one can call method (defined in class B's protocol) of class A from class B.
Below is overview of implementation of delegate chain through A -> B -> C.
Class A
Conforms protocol B
It has object of class B
Assign instance of class A(self) to delegate property of class B
In class A, implement protocol methods defined in class B
Class B
Define protocol with methods
Define property of generic type that act as delegate instance
Conforms protocol C
It has object of class C
Assign instance of class B(self) to delegate property of class C
In class B, implement protocol methods defined in class C
Class C
Define protocol with methods
Define property of generic type that act as delegate instance
I hope this will help you understand how delegate works in iOS.
Now in you case, you can conforms protocol of class B and class C into class A (if you don't want any modification into Class B and simply call upper layer's delegate methods).
See below overview
Class A
Conforms protocol B
It has object of class B
Assign instance of class A(self) to delegate property of class B
In class A, implement protocol methods defined in class B
Conforms protocol C
It has object of class C through object of class B
Assign instance of class A(self) to delegate property of class C
In class A, implement protocol methods defined in class C
Class B
Define protocol with methods
Define property of generic type that act as delegate instance
Class C
Define protocol with methods
Define property of generic type that act as delegate instance

Custom Delegate for a custom View

I m using Xamarin for iOS and I have a custom View which inherit from UIView.
I would like to add a custom delegate to that view.
So far I found that:
Delegate (not useful) example
I want my delegate to be on his own and won't inherit from any other known delegate.
There is no delegate property on UIView (see Apple docs). It does exists in some subclasses, like UITextView (and other types).
What you can do (beside using the base classes provided) is:
(with the unified API) create your own classes that implements the IUITextViewDelegate interface and assign it to the Delegate property;
Create any class that conforms to the delegate (i.e. minimally all required members), add the required [Export], and assign it to the WeakDelegate property.

Inheritance In Objective - C?

Okay, so my question itself states what i am asking.
I have a 3 view controllers. All the three of them are inheriting from a class (MainViewController).
Now what i want to ask is, is it possible in Objective C that suppose I have another class which has some variables and functions which i do not want to include in the MainViewController class, and pass this to one of the ViewControllers.
So if i number my view controllers, and let the other class be SecondClass.
1st, 2nd and 3rd ViewControllers inherit functions and variables from MainViewController.
If i want 2nd ViewController to inherit SecondClass also, then am i allowed to perform this kind of operation in Objective - C??
Objective-C is a single-inheritance language. Each class can inherit from exactly one superclass.
You can work around that with forwardingTargetForSelector: if you're absolute desperate but the neater and usually smarter thing is to compose functionality by saying that the second view controller owns an instance of SecondClass in addition to being a subclass of MainViewController.
You can see an example of Apple doing that in UIWebView. It isn't a subclass of UIScrollView but it uses a scroll view and exposes that instance (as of iOS 5) for outside actors via a property, scrollView.
Objective-C does not allow multiple inheritance. Check out this post for a great solution that uses composition.
Objective-C multiple inheritance
In objective C there is no support for multiple inheritance. Instead you can use either protocols or categories.
In addition you can use dynamic typing as well. Check out following link.
http://support.apple.com/kb/TA45894

Can a subclass of B (which inherits from class A) inherit from a subclass of A instead of A itself?

I'm working on an accessibility project for an iOS application. Because accessibility does not act quite as advertised, I have to override accessibilityFrame, accessibilityActivationPoint and pointInside:withEvent in a subclass in order to expand the region recognized by VoiceOver (for both drawing and touch recognition) beyond the "natural" bounds of the control view. So, in order to change the VoiceOver bounds of a UIButton I have to subclass that class and then add these three methods. In order to do this for a UILabel I have to add another subclass with the code, and so on.
I can refactor the code in these methods to a central location, but I was wondering if this can be done more elegantly with inheritance. I'd like to put this code into a subclass of UIView (maybe called UIViewAccessible) and then create a subclass of UIButton called UIButtonAccessible which inherits from UIButton which would in turn inherit from UIViewAccessible instead of UIView. Is this possible, or can something like this be done with a category?
Edit: According to the docs, you can't really achieve this with a category:
If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime.
Is there some other way to do this?
To answer your question, no, it can't, since your UIViewAccessible is a second degree sibling to UIButton in the inheritance chain (both inherit from UIView at some point). But I guess you already knew that. As for a solution, you could wrap around your UIView accessible classes a decorator and use protocols for strong typing. That way you'll keep the code in one place. I've described this technique here in more detail (although for a different purpose, it's the same situation).
For the views that would support accessibility you'll have to do this:
#property (nonatomic, strong) UIView<MyAccesibilityProtocol>* view;
//self.view can come from the nib or previously created in code
self.view = [[AccesibilityDecorator alloc] initWithDecoratedObject:self.view];
//you can then use self.view like any other UIView,
//and because it also implements an
//accessibility protocol, you can use the methods
//implemented in the wrapper as well.
//more than that, you can control which methods to override
//in the AccesibilityDecorator class
[self.view addSubview:otherView];//could be overridden or not
[self.view myAccesibilityMethod];//custom method declared in the protocol

How to make My UIControl subclass as superclass of programmatically created UIElements?

In my application I want to associate NSMutableDictionary to all UIElements (UIButton, UILable, etc), I can easily achieve this by subclassing each element, but I just want to know if I can make my own UIControl subclass -with a property of type NSMutableDictionary-, as superclass of all programmatically created UIElement s in anyway, so that I can reduce the number of subclasses.
Here like this
#interface UIControl : MyControls
{
}
#property(nonatomic,retain) NSMutableDictionary *details;
#end
and make MyControls as superclass of all programmatically created UIElements
You can do this, not by subclassing, but by adding your own properties and methods to UIControl itself (the superclass of UIButton, UILabel, etc.). These will then be inherited by any standard buttons, labels, etc. that you instantiate. Objective-C lets you add your own methods very easily using Categories. However, you can't add instance variables via categories. To do that, you need to use Associative References which are documented in the Objective-C Runtime Reference.
There's a good tutorial on how to do this here.
By the way, I don't necessarily disagree with inturbidus. But if you're sure you want to go this route, that's how you'd do it.

Resources