Where use factory and When ?

187 views
Skip to first unread message

BruceDdd

unread,
Aug 26, 2020, 3:58:19 PM8/26/20
to DDD/CQRS
I studying with major attention the factory "layer" 
so my doubt it's 

a factory (a class factory) can be use as dependency ? 
or not  ?

When use a factory in which cases ? 

Seiji Manoan

unread,
Aug 31, 2020, 1:21:50 AM8/31/20
to ddd...@googlegroups.com
whenever you need to build an Entity or Aggregate (AR) with complexity

...or avoiding repetitive parameters/tasks...

Look,

Player entity (or full AR) for instance, it took a Name, Number, Team, Position, Flags, Nickname/Alias, Height, Weight, etc...

So we can have a Factory to build an Entity with those details for ease.

BTW it isn't a layer itself

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dddcqrs/d1ed90f6-f9c7-41f7-8fed-16ebd75cfb6an%40googlegroups.com.

roberto diana

unread,
Aug 31, 2020, 3:26:34 PM8/31/20
to ddd...@googlegroups.com
thanks for answer, 

Il giorno lun 31 ago 2020 alle ore 07:21 Seiji Manoan <seos...@gmail.com> ha scritto:
whenever you need to build an Entity or Aggregate (AR) with complexity

...or avoiding repetitive parameters/tasks...

this it's the key concept, but also a pragmatic way ? (btw I agree...) 
But the factory isn't a "tool" to avoid direct dependency with concrete implementation ? 

My pragmatic way it's 
- if I need to build complex object, factory it's OK 
- if I need to avoid coupling with concrete class, factory it's OK  
The last step,make me think if to use factory as dependency or only the interface and use a factory first 

Sorry for the banal questions, I read a lot of article also Blue, Red books, but this concept isn't totally clear to me
 
Look,

Player entity (or full AR) for instance, it took a Name, Number, Team, Position, Flags, Nickname/Alias, Height, Weight, etc...

So we can have a Factory to build an Entity with those details for ease.

BTW it isn't a layer itself

Ya in fact I used the double apex :-) 



Em qua., 26 de ago. de 2020 às 16:58, BruceDdd <robert...@gmail.com> escreveu:
I studying with major attention the factory "layer" 
so my doubt it's 

a factory (a class factory) can be use as dependency ? 
or not  ?

When use a factory in which cases ? 

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dddcqrs/d1ed90f6-f9c7-41f7-8fed-16ebd75cfb6an%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.

Valentin Niță

unread,
Oct 20, 2020, 7:14:58 PM10/20/20
to DDD/CQRS
- if I need to avoid coupling with concrete class, factory it's OK 

It is not, because you still use concrete classes and cannot swap implementations; if you want to avoid coupling completly, you should have an interface for the factory, so that you don't depend on its implementation.

BruceDdd

unread,
Jan 7, 2021, 2:58:50 AM1/7/21
to DDD/CQRS
Hi, 
Il giorno mercoledì 21 ottobre 2020 alle 01:14:58 UTC+2 vald...@gmail.com ha scritto:
- if I need to avoid coupling with concrete class, factory it's OK 

It is not, because you still use concrete classes and cannot swap implementations; if you want to avoid coupling completly, you should have an interface for the factory, so that you don't depend on its implementation.
Yes, following DDD style, only interface... also for the factory  
Reply all
Reply to author
Forward
0 new messages