Jump to content

  • Log In with Google      Sign In   
  • Create Account


Caburé

Member Since 29 May 2008
Offline Last Active Apr 01 2013 03:27 PM
-----

Posts I've Made

In Topic: The Singleton Pattern: To be or not to be [used]?

09 November 2012 - 09:52 AM


That was a rethorical question, I already knew how to create a static class in Java.


Posted Image who said anything about static classes?
My entire point is to avoid static stuff actually Posted Image . What I meant was, what do you use to store your precomputed values? A standard class, plain and simple.


Yes, you are right.

In Topic: The Singleton Pattern: To be or not to be [used]?

09 November 2012 - 09:48 AM


That was a rethorical question, I already knew how to create a static class in Java.

He's not talking about a static class, he's talking about a normal class. Static data comes with many of its own pitfalls, even when that static data isn't truly global.


(I mean Java)

if I put a

public static final int x = 1;

in any normal class, that class is both global and static: is immutable because must hold the final value in at least one of its fields.. even without having static fields, in Java.

Every class in Java is static. Not every instance.

In Topic: The Singleton Pattern: To be or not to be [used]?

09 November 2012 - 09:40 AM

Global variable is already bounded in a scope.. do you mean that, when someone uses an API, all its singletons used internally must be visible for the programmer? I don't believe.

Ok. You refer a design pattern.


I was dumb and did not payed enough attention to it in the first post, in the beginning of the topic, sorry.

In Topic: The Singleton Pattern: To be or not to be [used]?

09 November 2012 - 09:33 AM


How would you store, for example, trigonometry tables?


class TrigonometryTables
{
...
}

Posted Image
It DOES NOT HAVE to be one. If your application only needs one, you application will instance it once and make it available to its subsystems.
In other words: why making assumptions on an application behavior if you dont have to?


That was a rethorical question, I already knew how to create a static class in Java. You mean why don't copy/paste Sun's/Oracle's formal definitions ? Because I thought it is a forum to interchange experience (this is rethoric again), not conceptual aspects of formal oop inspired by how philosofically the real world binds into the structure of a program and how beautiful it may become, in the aspect of fitting in the common-use of objects, the reference to singleton classes within the code.

I just said how I like to use singletons: reutilization of already created metadata valid in global level,everytime, with no specific meaning (and metadata doesn't have a context specific to an object but is the result of interactions of them, having no fit within them without extra-redesign). If the topic is how pretty it fits into the aspects of OOP... the name of the topic should be changed to "why do we still need to use singletons when it is conceptually outside the formal view of the floating round world of objects, resembling old days of procedural programming?".

I just answered the topic. If it fits or not the formal definitions of a design pattern instead of what the term means by itself.. that is another issue.

In Topic: The Singleton Pattern: To be or not to be [used]?

09 November 2012 - 09:02 AM


METADATA:

There are many times when a program needs to store and reference data that is a result of processing and that can be used again. How will you store metadata? I like to use singletons for structural/constant data/flags/metadata(temporary) instances, when the complexity of creating new instances and having it loading its data from something/somewhere doesn't worth as simply acessing it straight like cache of processors is used and Windows Registry (always in memory).


sorry it doesn't float at all.
It doesn't have to be a ONE! You create it ONCE, and pass it around or publish it to objects interested in it.
You are talking about trading memory for computation costs.. it doesn't have anything to do with SINGLENESS and globality of scope.



Singleton is single instance. It does not necessarily mean global scope (you can create a singleton in the scope of a package, for example).
Singleton is static - that is why there is a static word in Java (and not, again, necessarily, a global pointer/variable).
If you could reraise the data of a singleton just by making a new instance without costs, what would be the reason to use static classes (singleton) - that is what I am explaining?


How would you store, for example, trigonometry tables? If you can't see that, every time you declare a public static final int, the class where you declared it becomes a singleton, conceptually: is accessible in global scope and has only one static instance - the class itself. In Java, you can even set/change static variables at runtime (but not final variables).

I just said how I like to use SingleTons : to store metadata. I didn't argue that it is the only way to do that. But.. ppl seem to be stuck in just one technique.


After all, I am posting in the wrong place, I forgot to tell that I was meaning Java as programming language.

PARTNERS