This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / In the MVC world, what is the singleton? Thanks!
-guelpher(Guelph);
2010-7-24
(#6194359@0)
-
A singleton is a class that has only one instance. Is it safe to say a controller needs to be a singleton?
-zzhang(zz);
2010-7-24
(#6194374@0)
-
I don't know, but are you sure MVC here means Model-View-Controller? could it be Microsoft Visual C++ ?
-guelpher(Guelph);
2010-7-24
(#6194414@0)
-
As I know. MVC(Model-View-Controller) is a pattern, singleton is another pattern. In some cases, Controller is implemented as a singleton (only one instance in the whole runing env).Both MVC and singleton are design patterns, so they are not relate to any language. You can implement those patterns by java, c# or c++ depending on what you need.
-ejbeqhouse(ejbEqHouse);
2010-7-24
{163}
(#6194451@0)
-
so in MVC point of view, Singleton is only related to controller? it is just a design partten of controller? is there anything more than the controller?
-guelpher(Guelph);
2010-7-24
(#6194482@0)
-
MVC is a pattern, singleton is another pattern. They are indepent with each other. There are lots of other cases using singleton beside the controller. Which one should be used or if you should combine them together depends on what you need.
-ejbeqhouse(ejbEqHouse);
2010-7-24
(#6194518@0)
-
but if somebody ask: in MVC point of view, what is Singleton ? what is it asked about? Thanks!
-guelpher(Guelph);
2010-7-24
(#6194568@0)
-
Just reply in the way that I did. Then you can explain it in details what ejbEqHouse DX explained it to you.
-zzhang(zz);
2010-7-24
(#6194577@0)
-
Plus, a view can be a singleton as well. MVC and Singleton are two different patterns. MVC is about the way how three layers communicate with each other. Singleton is about how many instances of a class is allowed in its life cycle.
-zzhang(zz);
2010-7-24
(#6194583@0)
-
nice, thanks!
-guelpher(Guelph);
2010-7-24
(#6194874@0)
-
Under most situation, the model in a MVC pattern should be a singleton.View and controller should not be singleton, but as others said, singleton means something should be really single, like the premier of canada, if we got 2 or more, there's a trouble.
-c7et11n(拖泥虫);
2010-8-15
{184}
(#6229975@0)