Singletons or static members for Lightbox clones?

1 view
Skip to first unread message

stratboy

unread,
Nov 19, 2009, 3:48:10 AM11/19/09
to MooTools Users
Hi, I was wondering: should It be right to make classes like my
Milkbox or lightbox clones be singletons or maybe implement only
static methods (Milkbox.method() instead of milkbox.method())? My
question comes form the fact that it's not so realistic to have more
than 1 instance per page of a class like Milkbox.

So, what do you think about these thoughts?

Fábio M. Costa

unread,
Nov 19, 2009, 7:22:04 AM11/19/09
to mootool...@googlegroups.com
If your going to have one instance of the widget (one and only one, not more than this, nor in the future), then make it a singleton...
But if your thinking about making a milkbox that if you create another instance it splits the modal panel into 2 and opens the new one there... (hehe) than you could stay the way you are atm.
But its fine to have a singleton as long as you cant have more than one widget of the same kind.

--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces

stratboy

unread,
Nov 21, 2009, 3:10:42 AM11/21/09
to MooTools Users
Ok thank you, I'll go for a singleton in the next milkbox version.
One more question though: so I guess you think that a static class is
not suitable for milkbox. I'm sure you're right, but could you explain
why?

:) Thank you

Steve Onnis

unread,
Nov 21, 2009, 5:30:50 AM11/21/09
to mootool...@googlegroups.com
Is making it a singleton going to improve it in anyway? From what you are
saying all you will be doing is removing the option to have multiple
milkboxes on one page

stratboy

unread,
Nov 21, 2009, 9:28:57 AM11/21/09
to MooTools Users
Yes, that's my goal. Mainly because in fact, that should NOT be an
option, since multiple instances could cause problems, and also
milkbox is built to manage all galleries alone.

Anyone can speak about using a static class instead of a singleton?
Maybe a too hard question? :) Any guru listening out there? :)
Reply all
Reply to author
Forward
0 new messages