Possible Duplicate:
Difference between static class and singleton pattern?
i am not able to understabnd the difference b/w static class and singleton class.
in single ton class we make sure we cretae only one object and no more objects are created.
in a the static class also there is no need to create an object we can call the properties and methods directly using the static class name.
here both looks same so whats teh use of using creating single ton class.
any help on this would be great.
In Static class, there is no object. You directly call methods on the static class.
In Singleton, there is an object however, there can only be one instance of it.
Singleton is useful in conditional creation a resources intensive object. For ex, your application might need a connection to remote database. You might want to make it as singleton to limit the number of connections and also to ensure that its only created when required.
Static class and methods are more like utility functions which can be called whenever required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With