Re: Re: referencing Application classes from non-component classes
Re: Re: referencing Application classes from non-component classes
- Subject: Re: Re: referencing Application classes from non-component classes
- From: "Joe Little" <email@hidden>
- Date: Sat, 26 Aug 2006 00:37:44 -0700
On 8/25/06, Mike Schrag <email@hidden> wrote:
> Any examples of the dirty way? I'll check the backlog of emails as
> well.
Assuming your EO's are in the same project as your Application, there
really isn't anything you need to do except import your Application
class and call the method. There's nothing particularly special
about Application compared to any other Java class.
>> A possible alternative would be to have a singleton
>> ApplicationSettings class that Application pushes values into, but
>> that you can talk to from your model without dragging in
>> WOApplication dependencies along the way.
>
> Hm.. I thought I did this already. I currently reference an instance
> of class with all my values that is instantiated by Application. The
> only reference of the instance if via the Application, so I'm
> obviously missing some fundamental design pattern I haven't touched
> upon before.
The problem is that your EO has to pass through Application to get to
this class you've instantiated, which means you're dragged a really
high level dependency (Application) into a really low level model
object (your EO). The alternative I was referring to is more like
(this is typed into the mail message, so forgive any syntax errors):
public class ApplicationSettings {
private static ApplicationSettings _instance;
public static synchronized ApplicationSettings instance() {
if (ApplicationSettings._instance == null) {
ApplicationSettings._instance = new ApplicationSetings();
}
return ApplicationSettings._instance;
}
private ApplicationSettings() {
}
public String stringValueForKey(String propertyName) { .. }
public void loadFromProperties(Properties properties) { .. }
...
}
in Application:
ApplicationSettings.instance().loadFromProperties
(System.getProperties());
in EO:
String settingValue = ApplicationSettings.instance
().stringValueForKey("somethingEOKnowsAbout");
Thanks. I'll just need to use my simple propertires class with the
constructor/instance mechanism you listed and drop the instance
variable there. The rest will be the various (Application)application
references throughout the code. Again, thanks again for the guidance.
ms
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden