• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: referencing Application classes from non-component classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: referencing Application classes from non-component classes


  • Subject: Re: referencing Application classes from non-component classes
  • From: Mike Schrag <email@hidden>
  • Date: Sat, 26 Aug 2006 01:48:14 -0400

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");


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


  • Follow-Ups:
    • Re: referencing Application classes from non-component classes
      • From: Paul Lynch <email@hidden>
    • Re: Re: referencing Application classes from non-component classes
      • From: "Joe Little" <email@hidden>
References: 
 >referencing Application classes from non-component classes (From: "Joe Little" <email@hidden>)
 >Re: referencing Application classes from non-component classes (From: "Joe Little" <email@hidden>)
 >Re: referencing Application classes from non-component classes (From: Mike Schrag <email@hidden>)
 >Re: Re: referencing Application classes from non-component classes (From: "Joe Little" <email@hidden>)

  • Prev by Date: Re: Re: Re: referencing Application classes from non-component classes
  • Next by Date: Re: Re: referencing Application classes from non-component classes
  • Previous by thread: Re: Re: Re: referencing Application classes from non-component classes
  • Next by thread: Re: Re: referencing Application classes from non-component classes
  • Index(es):
    • Date
    • Thread