Reputation: 5372
I'm sure this has been asked before in a better way, but I'm trying to understand how interface elements relate to classes. My application is very simple, mainly an NSTextView
that gets populated with some output logs.
I've been just using AppDelegate
to handle most of my app's function, but now I want to break things up a little. So I have created a Logger
class that has all the code relating to the logging part, including handling updating the NSTextView. So what I'm not sure about is should I hook the NSTextView's referencing outlet directly to the Logger class, or should I keep these two things decoupled and just pass a reference of the NSTextView to the Logger object?
Upvotes: 0
Views: 25
Reputation: 5698
Your Logger
, on top of it's logging logic, sounds like it also contains presentation logic-- which just takes your model (data), formats it, then directly passes it to your NSTextView
to display it.
It sounds like your NSTextView
is inherently connected to your Logger
. If you connect your NSTextView
to an outlet in your Logger
, you will be able to easily set the stringValue
of the NSTextView
through that reference.
Also, as you said the alternative would be to have another object obtain a reference to your NSTextView
, then pass it to your Logger
. Because your Logger
controls the presentation of your NSTextView
, that wouldn't be necessary. In fact, it should be the other way around-- you can make your IBOutlet
public (by placing it in your header file, instead of in the class extension in the implementation file), if any other objects need a reference to your NSTextView
(Like a window that wants a reference to that view to display)
So I believe you do in fact want to connect the two
Upvotes: 1