Requring static class setter to be called before constructor, bad design?
Posted
by
roverred
on Programmers
See other posts from Programmers
or by roverred
Published on 2013-10-19T21:46:29Z
Indexed on
2013/10/21
10:15 UTC
Read the original article
Hit count: 156
design
|static-methods
I have a class, say Foo,
and every instance of Foo will need and contain the same List object, myList.
Since every class instance will share the same List Object, I thought it would be good to make myList
static and use a static function to set myList
before the constructor is called.
I was wondering if this was bad, because this requires the setter to be called before the constructor? If the person doesn't, the program will crash. Alternative way would be passing myList
every time.
© Programmers or respective owner