Skip to content

Commit 771ad9a

Browse files
authored
factoryMethod: add a more TypeScript-y Factory fn
Creating a class to only add a static method will generate a prototype with a function directly added to it, when it could generate directly the object with the function added as a property.
1 parent 9c653ca commit 771ad9a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

factory_method/factoryMethod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace FactoryMethodPattern {
1717
}
1818

1919

20-
export class ProductFactory {
21-
public static createProduct(type: string) : AbstractProduct {
20+
export namespace ProductFactory {
21+
export function createProduct(type: string) : AbstractProduct {
2222
if (type === "A") {
2323
return new ConcreteProductA();
2424
} else if (type === "B") {

0 commit comments

Comments
 (0)