what is the difference between static method of the class, module method and static method of the module?
Alex Rønne Petersen
alex at lycus.org
Wed Jun 20 08:47:05 PDT 2012
On 20-06-2012 17:45, ref2401 wrote:
> I have a class, and I want to write factory methods which will
> encapsulate different ways of creating instances of this class.
> I can do this in 3 ways:
>
> // static method of the class
> public class Item
> {
> public static Item createItem_1() { ... }
> }
>
> // module function
> public Item createItem_2() { ... }
>
> // static function of the module
> public static Item createItem_3() { ... }
>
> Which way should I choose? What are their pros and cons?
The static keyword has no effect on module functions, so 2 and 3 are
equivalent. There is no significant difference between static class
methods and module functions.
--
Alex Rønne Petersen
alex at lycus.org
http://lycus.org
More information about the Digitalmars-d-learn
mailing list