Design Pattern: Is the Universe Object a Singleton or Static or either way.

Hi All,
1. I've read this thread: static versus singleton
http://forum.java.sun.com/thread.jsp?forum=425&thread=401035&tstart=105&trange=15
2. Now, specifically if you were to model the Universe Object, what would you choose? a Singleton
or a Static Class or either way depending on your design point of view?
(either way depending on your design point of view imply there is more than one solution to a problem.)
Basically, I'm looking for is the justification of one (singleton) or the other (static) or doesn't matter
in addition to the pure technical pros and cons (or avantage/disavantage) of singleton versus Static (see pt. 1)

<dubwai>
What's 'the Universe Object'?
</dubwai>
Sorry, for not being clear. My assumption is that every body would undertand the word 'Universe' immediately. So with this clarification. I hope you will have more input. Thanks.
public class Universe //Singleton
     private static Universe instance = new Universe(); 
     private Universe()
     public static Universe getInstance() 
       return instance;
     public void do() 
public class Universe  //Static Class like Math class for example
     public static void do() 
     ...all other methods are static
<os>
Personally, I'd make the universe a singleton.
The universe is an 'object', not a class, and if alternate universes are proved to exist you can create new instances,
and not treat it as a singleton any more, without much rewriting (a static implementation would need a total rewrite).
</0s>
1. Keywords: Personally and alternate universes are proved to exist.
Yes, this is the kind of reasoning I'm looking for. By that I mean when we design a class, our reasonning should not depends
on the 'pure' technical concepts of what Singleton class or Static class can do but rather depending on the reality
of the world. And then from that understanding we would choose a Singleton or Static class. This is what I meant by 'Either way, it doesn't matter' which depend on one's view about of existence of the universe whether it's unique or not. In your case (Os), you prefer Singleton because of the possibility of alternate universes.
2. Now, let's admit, there is only one Universe, would you still prefer Singleton class over Static class? for all the techincal reasons that you said
"As a singleton,..."
"It would also probably be useful to treat the universe as a generic Object..."
OR just because a Singleton would be 'safer' to cover the possibility of design extension in that can cover all cases (alternate as well)

Similar Messages

  • Design pattern -- using the correct one...?

    I'm in need of some advice regarding design patterns in general.
    I have a prototype whereby Objects B, C and D observe Object A's attribute (let's call it theAttribute -- imaginative, eh? )
    In my system, every time theAttribute is changed, I've implemented the Gang's Observer pattern so that the observer objects are notified (...and do something with the information that Object A has changed in some way... they basically update a theTimestamp attribute when the subject's updated... but that really is beside the point right now).
    However, only ONE observer will ever be created for each observable subject.
    To my dismay, I've just been reading on the IBM Research site that the memory implications of this are horrendous (that for potentially a great many subjects only having a few observers each is bad practice) -- d'oh.
    I've looked at other ways I could achieve what I need to without the above practice, but the only things I can come up with are the Mediator pattern or the State pattern, neither of which I'm sure are ideal (the former because of I'm worried that it'd be total overkill, the latter because I don't really need dynamic reclassification if the truth's told, I think).
    Anyone got any thoughts on this? (I've considered referencing observers with their observables using a hash table but don't really wish to go down that route unless absolutely neccesary... it seems a bit like putting electrical tape over a sparking wire :) I'd rather just do it properly).
    Sarah.

    However, only ONE observer will ever be created for each observable subject.If you can absolutely, positively, definitely, mathematically, logically, legally
    and morally prove that fact, indeed, you're wasting some resources here,
    a couple of hundred bytes mayhap ...
    In the mean time, keep your Observer/Observable pattern/implementation
    or have a look at the PropertyChangeSupport class ...
    kind regards,
    Jos

  • Please suggest me a suitable design pattern for the scenario below

    Hello,
    I have around three to four methods in a class. And their invocation is mutually exclusive that only one of them can be called depending upon the scenario. usually to acheive this, what we do is, write if and else loops and depending upon the scenario, we call the method correspondingly. i thought of avoiding this if else loops and would like to know whether there is any possibility for achieving the same without if else loops? if yes how do we do this? is there any design pattern available?
    Thanks, Aravinth

    Hi,
    In java we have something is called reflection; reflection is very powerful API. I would suggest the below to start with
    public class Foo {
         public static final String METHOD_ONE="methodOne";
         public static final String METHOD_TWO="methodTwo";
         public void methodOne() {
              System.out.println("method one is being invoked..");
         public void methodTwo() {
              System.out.println("method two is being invoked..");
         public void methodInvoker(String scenario) throws Exception {
              Class clazz =this.getClass();     
              Method method =clazz.getMethod(scenario, new Class[]{} );
              method.invoke(this, new Object[]{});
         public static void main(String args[] ) throws Exception  {
              Foo foo = new Foo();
              foo.methodInvoker(Foo.METHOD_ONE);
              foo.methodInvoker(Foo.METHOD_TWO);
         }I hope this could help
    Regards,
    Alan Mehio

  • Flex design pattern for BlazeDS transfer objects

    Dear Community,
    I have a question regarding the nature of objects transferd from BlazeDS backend to the Flex client.
    According to some adobe docs all the presentation logic should be in flex and BlazeDS should provide only services.
    The question is what kind of transfer objects should be used? with what level of abstraction?
    To make it more clear let's talk about a simple forum application like adobe forums.
    I have created a Forum service, which returns a Forum transfer object, which has a List of Threads, with each thread having a List of Messages.
    Flex gets the Forum transfer object and does all the presentaiton work.
    This is a very nice seperatin of concerns architecture BUT there are two major performance issues:
    - when the forum becomes bigger the transfer object will be huge
    - the flex will use huge client resources to create the presentation of the forum transfer object.
    So my question is what is your strategy/ design pattern for such a problem.
    An obvious answer would be create services that include the presentation logic and use transfor objects like ThreadListPage which will include only the first 10 threads.
    Thanks in advance

    I think you are going to get a few varied types of answers to a general question like this, but I will comment on a few things.  First, you should only be transmitting the data that you need to use or display to the user at the time.  If this forum was implemented in Flex (I wish) you wouldn't transfer the text for all the threads.  You might not transfer the thread text at all (just the subjects), you'd make calls back to the server to fetch that data when and if you need it.
    Also, I think you are overestimating the resources required for the Flex "presentation layer".  If you think about it, these workstations we have here are pretty idle most of the time when you're at a website.  Nowadays there's plenty of processing power just sitting there waiting, so as long as your design isn't flawed the CPU or memory are rarely going to be a bottleneck with Flex.
    The way I design, BlazeDS (or GraniteDS etc) should mostly just be "serving data".  There is some flexibility available, for example I don't see a problem with putting certain types of business rules (such as a limit on the number of results that can be recieved in a search) within server side code, and validation rules on the Flex side.  So there's not too many "industry standards" in Flex yet beyond maybe what's done in the various standard architectures, at least not that I'm aware of.
    You might find it beneficial to look into some of the various frameworks/architectures available like Cairngorm, Mate, Swiz, and so on.  Learning how they work (looking at examples) would probably answer some of your questions too.

  • HT2534 I am from the U.S, now currently in the Czech Republic. Just bought an iphone with vodafone. I can't get past the account setting on itunes, etc...either way, How do I get ENGLISH SPEAKING HELP instead of being redirected to the Czech Language stor

    I am somewhat new to apple products. I am from the U.S. and currently studying in the Czech Republic.
    I have an itouch with an apple ID, but lately I can't get it to charge or work. After pluggin the usb recharge cable to the computer at my universities facility, it gives a black page with a picture of the cable and the arrow pointing to itunes logo. The school's computer labs don't have i tunes or anything like that.
    I also just got an iphone 4S and have been trying to set up and i can't seem to complete the process for the itunes so i can install the apps i had in the itouch and also to get new apps. It stops me and says to contact the itunes for support right after the input of address and phone number information, etc...
    The purchase was made in the czech republic from a vodafone store, but if i remember right i configured it to US settings so I don't have to deal so much with everything showing up in Czech.
    I tried getting help by going to the support, but after putting in my  name, email, phone number for scheduling a call with them it rejects the phone number because i am putting in my czech phone number. Putting in my previous US number would be useless because I am not in the US and that number is probably inactive.
    I would to get some English speaking support while being here in the czech republic.
    Any advice?
    -peteMD-

    If you are completely confident that you didn't hide it, then you purchased those with different apple id. If you completely confident that you purchases with same apple id then you have hidden it. One of the other or you are speaking about a miracle. While miracles are possible they are not very likely. Remember
    Occam's razor?

  • Design Pattern help needed for MDI application

    Hi,
    I am writing an mdi application which contains a JSplitPane. The left pane contains a JTree and the right contains a JDesktopPane which houses n number of JInternalFrames. The JInternal Frames need access to the JTree. Also both panes (objects w/in) need access to elements of the JFrame. I am currently implemeting access by making most of the JFrame objects static and creating getter/setter methods for access. Does anyone know any desing patterns I might use to solve this dilemma?
    Thanks,
    John

    The observer design pattern causes the child objects to chage state when the parent changes state. The type of pattern I need would allow the child objects of the parent JFrame to be available globally without having to make them static. I am wrong in this? Would the observer pattern solve this issue.

  • ABAP objects design patterns

    hi all,
        can any one send me the Design patterns used for ABAP objects programming in ABAP. eg mvc and sample code which uses the design patterns
    cheers
    senthil

    Of course that program is not an object design pattern
    (Its just a little ABAP Objects syntax demo that I wrote  years ago
    I don't know about a list of OO design patterns implemented in ABAP Objects.
    A very simple one, a Singleton might look like this:
    <b>* cl_singleton: Eager Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS: class_constructor,
                       get_singleton RETURNING VALUE(singleton)
                                               TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD class_constructor.
        CREATE OBJECT singleton.
      ENDMETHOD.
      METHOD get_singleton.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.
    cl_singleton: Lazy Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS get_singleton RETURNING VALUE(singleton)
                                              TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD get_singleton.
        IF cl_singleton=>singleton IS INITIAL.
          CREATE OBJECT cl_singleton=>singleton.
        ENDIF.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.</b>

  • What is the best design pattern for this problem?

    No code to go with the question. I am trying to settle on the best design pattern for the problem before I code. I want to use an Object Oriented approach.
    I have included a basic UML diagram of what I was thinking so far. 
    Stated simply, I have three devices; Module, Wired Modem, and Wireless Modem.
    In the Device Under Test parent class, I have put the attributes that are variable from device to device, but common to all of them.
    In the child classes, I have put the attributes that are not variable to each copy of that device. The attributes are common across device types. I was planning to use controls in the class definition that have the data set to a default value, since it doesn't change for each serial number of that device. For example, a Module will always have a Device Type ID of 1. These values are used to query the database.
    An example query would be [DHR].[GetDeviceActiveVersions] '39288', 1, '4/26/2012 12:18:52 PM'
    The '1' is the device type ID, the 39288 is the serial number, and the return would be "A000" or "S002", for example.
    So, I would be pulling the Serial Number and Device Type ID from the Device Under Test parent and child, and passing them to the Database using a SQL string stored in the control of the Active Versions child class of Database.
    The overall idea is that the same data is used to send multiple queries to the database and receiving back various data that I then evaluate for pass of fail, and for date order.
    What I can't settle on is the approach. Should it be a Strategy pattern, A Chain of Command pattern, a Decorator pattern or something else. 
    Ideas?

    elrathia wrote:
    Hi Ben,
    I haven't much idea of how override works and when you would use it and why. I'm the newest of the new here. 
    Good. At least you will not be smaking with a OPPer dOOPer hammer if I make some gramatical mistake.
    You may want to look at this thread in the BreakPoint where i trie to help Cory get a handle on Dynamic Dispatching with an example of two classes that inherit from a common parent and invoke Over-ride VIs to do the same thing but with wildly varying results.
    The example uses a Class of "Numeric"  and a sibling class "Text" and the both implement an Add method.
    It is dirt simple and Cory did a decent job of explaining it.
    It just be the motivation you are looking for.
    have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Code for singleton design pattern

    Hi,
    This is kalyan. Can u provide code for Singleton design pattern.
    Thanks in Advance

    public class Singleton {
      private Singleton() {
      private static Singleton instance;
      public Singleton getSingleton() {
        if (instance == null) instance = net Singleton();
        return instance;
    }Does it make sense?

  • SERVICE LOCATOR ?? Is it really an interesting Design pattern??

    Hi everybody,
    i've a problem with the J2EE Design Pattern "Services locator" (it's a singleton).
    It is said that by making use of a Service Locator we can :
    - hide to the client the complexities of initial context creation, EJB home object lookup,and EJB objectre-creation.
    - multiple clients can reuse the Service Locator object to reduce code complexity, provide a single point of control, and improve performance by providing a caching facility.
    But i would like to understand at which side should that service locator object reside??!!??
    If it is at server side then the clients need well an initial context in order to make a lookup on that object.
    Conclusion :
    the service locator doesn't hide the complexities of initial context!!
    Furthermore the client has to perform a look-up on that service locator object!! The only advantage left is caching facility.
    If it is at client side, each client needs his own services locator object
    Conclusion :
    multiple client don't reuse the same service locator. What's the advantage to be a singleton ???
    There is certainly something that i don't understand so help me please!! Thanks.

    Hi Yves,
    But i would like to understand at which side should
    that service locator object reside??!!??
    If it is at client side, each client needs his own
    services locator object
    Conclusion :
    multiple client don't reuse the same service locator.
    What's the advantage to be a singleton ???The service locator resides on the client side and is implemented as
    a singleton. Since it is possible that there could be multiple
    class loaders/JVMs on the client side, and therefore, multiple
    instances of the "singleton" service locator. This is typical
    in a distributed environment (e.g. servlets/JSPs in a web-tier
    cluster using service locator). Thus service locator is not
    a truly "distributed singleton" object. But, the empahsis
    is to design the service locator such that it does not hold
    any state that needs to be replicated across multiple
    instances across different JVMs as mentioned. Thus, there
    is no need for multiple clients to use the "same" service locator,
    but still the benefits of implementing this pattern is realized.
    By making it a singleton, and keeping it from holding state
    that needs to be replicated, we realize the benefits of this pattern.
    You may also want to visit the J2EE Pattern interest list
    and see these relevant discussions :
    Topic: Service Locator and passivation
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=1026
    Topic: Caching EJBHome interfaces
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=9226
    Topic: Using Service Locator for Data Source caching
    http://archives.java.sun.com/cgi-bin/wa?A1=ind0106&L=j2eepatterns-interest#31
    hope this helps,
    thanks,
    -deepak

  • Location manager design pattern?

    What is the best design pattern for using the location manager with intermittent but time-sensitive use? My app records location each time the user creates a photo, creates a note, records audio, etc and stores it using CoreData. The problem is the location manager has to spin for a bit to get the best reading, and in that time the user could easily have navigated the UI to delete the object they've created and create a new one. In that case I'd want to interrupt any location services active for the deleted object.
    Is a singleton the best pattern, keeping the active objects in an array and using @synchronize(object)...but running each in a different thread?
    Or assigning the location manager as a transient property of the object and calling stopUpdatingLocation if it gets deleted?
    Any thoughts? TIA...

    I created a singleton for this - seems to work quite well

  • Design patterns in portlet development

    Hello,
    I am a student at the Technical University in Munich, Germany and I am working on a university project on design patterns for portlets.
    The focus of my work is researching the best practices when developing a web portlet, especially which design patterns are the most suitable for portlets development.
    For example, the MVC pattern is one of the most popular design patterns for portlets.
    I am writing to you to ask which design patterns are used in the development of your portlets from the SAP Enterprise Portal.
    - What design patterns do you use for your portlets?
    - Do you use MVC among others?
    - Do you have your own design patterns?
    - Do you use any templates or guidelines for portlet development that involve design patterns?
    I am looking forward to your answer. Any answer would help with the research, as experts’ interviews are part of my work in the project.
    I appreciate any references you consider to be related to my search.
    Thank you,
    Julia Alexandrescu
    Department of Informatics
    Technical University Munich
    Email: [email protected]

    Hi raaj,
    I have a query related to this.
    I am a beginner to portlets.
    Say I have an existing struts application.What all do i need to modify or add to make a .portlet file out of it so as to make it deployable in Weblogic 8.1 SP3?
    Is adding a portlet.xml enough?
    if yes, what would the portlet.xml look like?
    Do i need to add a separate class as well?
    I couldnt get any sufficient answers from other forums.
    Can you please help?
    Thanks & Regards,
    Nishant

  • Design Patterns w/o EJB

    Greetings, I am attempting to build a JSF application while learning JSR 127 and a few of the J2EE design patterns. The problem that I am having is that I don't plan on using EJB/Spring with my project and many of the tutorials I have been able to find place a focus on the EJB/Spring implementation details which are both overkill for this project. That said, I want to learn the appropriate patterns to build a functional application without catching "pattern fever".
    I have a general idea of some of the patterns I need to use to get from the presentation tier to the data tier, such as Business Delegate and Data Transfer Object. However, I'm not sure I understand how to use these in conjunction with the managed beans facility. Do the managed beans contain (as in composition) the Business Delegate objects? Or do I use a DTO to push the data from the managed bean to the Delegate? How much if any logic do I put in the managed beans if I'm using them in this fashion (or are they basically just fields and getter/setters)?
    All comments or suggestions are sincerely appreciated,
    Jon

    Hi,
    Have you taken a look at Java BluePrints Solutions Catalog:
    https://blueprints.dev.java.net/bpcatalog/
    The Solutions Catalog focuses on different topics specifically so that you can pick and choose which articles are most interesting to you.
    -Larry

  • Get instance method and design pattern

    Hi All,
    1. I New to abap objects and i read the help and some stuff from the forum,
    l like to now more about design pattern in abap objects,
    2. I saw in some abap class the use of method of GET_INSTANCE i think it's from factory pattern , what is the pros. and cons to use this method ,when i should consider to use it ?
    Thanks in Advance
    Nina

    Hello Nina
    A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern.
    You should use the factory pattern when
    - you want to prevent "direct" instantiation (i.e. using a public CONSTRUCTOR method) by the developer
    - you want to hide the complexity of instantiation from the user of the class
    - the instantiation creates an implementation of an interface and you want to keep control of which implementing class is returned
    Regards
      Uwe

  • What is a design pattern?

    Howdy,
    I hear a lot of talk of deasign patterns in ABAP...
    My question is what on earth is a design pattern and why/how would it be useful?
    Any ideas anyone

    Hi Steve.
    The good point to start with design patterns is to read book "Design Patterns - Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. It gives strong, consistent understanding of patterns basis with real life examples.
    Short introduction extract:
    "Christopher Alexander says, "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice". Even though Alexander was talking about patterns in buildings and towns, what he says is true about object-oriented design patterns. Our solutions are expressed in terms of objects and interfaces instead of walls and doors, but at the core of both kinds of patterns is a solution to a problem in a context.
    In general, a pattern has four essential elements:
    The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two. Naming a pattern immediately increases our design vocabulary. It lets us design at a higher level of abstraction. Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and their trade-offs to others. Finding good names has been one of the hardest parts of developing our catalog.
    The problem describes when to apply the pattern. It explains the problem and its context. It might describe specific design problems such as how to represent algorithms as objects. It might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
    The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations. The solution doesn't describe a particular concrete design or implementation, because a pattern is like a template that can be applied in many different situations. Instead, the pattern provides an abstract description of a design problem and how a general arrangement of elements (classes and objects in our case) solves it.
    The consequences are the results and trade-offs of applying the pattern. Though consequences are often unvoiced when we describe design decisions, they are critical for evaluating design alternatives and for understanding the costs and benefits of applying the pattern. The consequences for software often concern space and time trade-offs. They may address language and implementation issues as well. Since reuse is often a factor in object-oriented design, the consequences of a pattern include its impact on a system's flexibility, extensibility, or portability. Listing these consequences explicitly helps you understand and evaluate them."
    Regards,
    Maxim.

Maybe you are looking for