473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why instantiate a class, all of whose methods, properties, and events are static?

Hi,

I'm learning the .net Bloomberg api, and it's main class has all of its
stuff static. The help then goes on to say that the class is
implemented as a singleton. It's cool I guess to make sure not more
than one instance can be made, but with everything in the class static,
I don't actually understand why even *one* instance is required.

What's the design rationale for this?

Oct 4 '06 #1
7 1447

sherifffruitfly wrote:
Hi,

I'm learning the .net Bloomberg api, and it's main class has all of its
stuff static. The help then goes on to say that the class is
implemented as a singleton. It's cool I guess to make sure not more
than one instance can be made, but with everything in the class static,
I don't actually understand why even *one* instance is required.

What's the design rationale for this?
Unless they're abusing the term "singleton" to mean a static class...?

Oct 4 '06 #2

Bruce Wood wrote:
sherifffruitfly wrote:
with everything in the class static,
I don't actually understand why even *one* instance is required.

What's the design rationale for this?

Unless they're abusing the term "singleton" to mean a static class...?
lol! That didn't occur to me! I'm new to oop/patterns/what-not, so I
tend to use all of its terms according to strict dictionary definitions
(more or less) - such a possible "liberty" with the lingo didn't even
cross my mind...

Oct 4 '06 #3
Hi,

sherifffruitfly wrote:
Hi,

I'm learning the .net Bloomberg api, and it's main class has all of its
stuff static. The help then goes on to say that the class is
implemented as a singleton. It's cool I guess to make sure not more
than one instance can be made, but with everything in the class static,
I don't actually understand why even *one* instance is required.

What's the design rationale for this?
If all the methods and properties in the class are static, the correct
denomination is "facade". In the facade pattern, the class acts as a
"wall" to "hide" the calls to objects. Facade classes are at the limit
between OOP and procedural programming, and should IMHO be used with
reason. To ensure that instantiation is impossible, facade classes have
a private default constructor.

A singleton class, however, ensures that maximum one instance of a class
exists at all time.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 5 '06 #4
Laurent Bugnion wrote:
sherifffruitfly wrote:
Hi,

I'm learning the .net Bloomberg api, and it's main class has all of its
stuff static. The help then goes on to say that the class is
implemented as a singleton. It's cool I guess to make sure not more
than one instance can be made, but with everything in the class static,
I don't actually understand why even *one* instance is required.

What's the design rationale for this?

If all the methods and properties in the class are static, the correct
denomination is "facade". In the facade pattern, the class acts as a
"wall" to "hide" the calls to objects. Facade classes are at the limit
between OOP and procedural programming, and should IMHO be used with
reason. To ensure that instantiation is impossible, facade classes have
a private default constructor.
That's not my understanding of the facade pattern. To me, the facade
pattern just presents a simpler interface, quite possibly still
involving creating an instance.

See http://en.wikipedia.org/wiki/Fa%C3%A7ade_pattern

(Unfortunately I don't have my GoF book here to check with...)

Jon

Oct 5 '06 #5
Jon Skeet [C# MVP] wrote:
>If all the methods and properties in the class are static, the correct
denomination is "facade". In the facade pattern, the class acts as a
"wall" to "hide" the calls to objects. Facade classes are at the limit
between OOP and procedural programming, and should IMHO be used with
reason. To ensure that instantiation is impossible, facade classes have
a private default constructor.

That's not my understanding of the facade pattern. To me, the facade
pattern just presents a simpler interface, quite possibly still
involving creating an instance.
I agree with Jon. Facade pattern and whether or not methods are static are
not related. The Facade pattern is a way to create a simple interface on
top of a complex system. An example would be if you have a fairly common
operation to perform that requires some complex coordination among other
objects. You don't want to do this coordination each time you want to
perform the operation. So you can create a facade class that exposes simple
method that does the complex coordination for you. Then you just create an
instance of the facade class, call its simple method and let it worry about
what is required to actually perform the action. The method might be static
or not, that is a design decision to be made based on other criteria.

I have seen imlpementations of facade classes that take in the objects they
are going to coordinate in the constructor. This allows for reuse,
especially if designed to interfaces rather than concrete classes. But
again, the implementation will depend on the needs of the specific scenario.
--
Tom Porterfield

Oct 5 '06 #6
Hi,

Tom Porterfield wrote:
Jon Skeet [C# MVP] wrote:
>That's not my understanding of the facade pattern. To me, the facade
pattern just presents a simpler interface, quite possibly still
involving creating an instance.


I agree with Jon. Facade pattern and whether or not methods are static
are not related. The Facade pattern is a way to create a simple
interface on top of a complex system. An example would be if you have a
fairly common operation to perform that requires some complex
coordination among other objects. You don't want to do this
coordination each time you want to perform the operation. So you can
create a facade class that exposes simple method that does the complex
coordination for you. Then you just create an instance of the facade
class, call its simple method and let it worry about what is required to
actually perform the action. The method might be static or not, that is
a design decision to be made based on other criteria.

I have seen imlpementations of facade classes that take in the objects
they are going to coordinate in the constructor. This allows for reuse,
especially if designed to interfaces rather than concrete classes. But
again, the implementation will depend on the needs of the specific
scenario.
Interesting. I got to say, I always thought of Facades as static
classes, with the exact purpose that you state, i.e. providing a simpler
access to a complex system. I never thought of making them non-static.
Or, rather, I already made such non-static classes, but I never thought
of them as facades ;-)

Thanks for clarifying.

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 7 '06 #7

Laurent Bugnion wrote:
If all the methods and properties in the class are static, the correct
denomination is "facade". In the facade pattern, the class acts as a
"wall" to "hide" the calls to objects. Facade classes are at the limit
between OOP and procedural programming, and should IMHO be used with
reason. To ensure that instantiation is impossible, facade classes have
a private default constructor.
Good to know - thanks! That makes the Math class in c# make more sense
now - it's describe as a classic example of functionality that really
is procedural in nature, so they dispense with the instantiation
process by making everything static. I don't know if they made the
constructor private or not, but it sounds like they *should*.

Nov 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin | last post by:
I am developing a windows application, which consists of few projects with many methods, functions, events etc., Is there any "tool" available with VS.net to find the total number of times each...
2
by: manohar.shankar | last post by:
Hi, I have been searching on this topic for quite sometime and didnt get any answer. Is there a way I can extend/add methods/properties to a C# class during runtime. eg., I have class:...
1
by: Ryan Taylor | last post by:
Hopefully a quick question. I remember seeing a guideline on Microsofts site that stated the recommended order for declaring members, properties, events and orders. As I am really trying to...
2
by: Sergey Ilinsky | last post by:
Well, I've been working with JS for three years and have a great experience here. But! I still have no really acceptable answer to the following question: What is the principle difference between...
3
by: Sam Sungshik Kong | last post by:
Hello! While using panel control, I wondered a thing. Panel class is subclass of Control class. Control class has KeyPress event and Focus() method, etc... Then Panel class must have them. I...
7
by: Mike P | last post by:
I have a class with a dozen+ properties, some of which will be set a value, and some not, depending on the constructor called. I also have a method which has only one overload and all of the...
2
by: DraguVaso | last post by:
Hi, I have a UserControl (MyUserControl) which has a DataGrid (MyDataGrid). I made a new UserControl that Inherits of my first UserControl: I named it MyInheritedUserControl. For some reason...
0
by: Shrage H. Smilowitz | last post by:
I have posted this question in the vision forum and got no response, so maybe one of the vb developers here can aswere me. In VB.net classes can have Properties (Attributes in UML), Functions...
1
by: davidw | last post by:
I found it seems there is a way to create a class with dynamic properties, I don't really need define each property? In ASP.NET, Profile is created with all profile items in web.config as its...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.