Factory class - DA, BL, or UI layer?

  • Thread starter Thread starter deko
  • Start date Start date
D

deko

Which layer should a Factory class go in?

DA - Data Access
BL - Business Logic
UI - User Interface

??
 
The same layer as the object it is designed to create. Put it anywhere
else will introduce unnecessary coupling between layers.
 
"deko" <[email protected]> a écrit dans le message de (e-mail address removed)...

| Which layer should a Factory class go in?
|
| DA - Data Access
| BL - Business Logic
| UI - User Interface

That would depend on whether its a Data Connection factory, a Business
object factory or a UI Widget factory.

Factories are a design pattern that can be used in all sorts of situations.

Joanna
 
The same layer as the object it is designed to create. Put it anywhere
else will introduce unnecessary coupling between layers.

So, should I have a factory in each layer (if needed), like this:

FactoryDA.cs
FactoryBL.cs
FactoryUI.cs

??
 
"deko" <[email protected]> a écrit dans le message de (e-mail address removed)...

|> The same layer as the object it is designed to create. Put it anywhere
| > else will introduce unnecessary coupling between layers.
|
| So, should I have a factory in each layer (if needed), like this:
|
| FactoryDA.cs
| FactoryBL.cs
| FactoryUI.cs

Not strictly, no. The Class Factory design pattern can be used for many
different purposes.

Sometimes, you don't need any factories, sometimes you will need more than
one in a layer.

There is no relationship between factories and layers, a class factory is
related to a given class hierarchy where you define abstract behaviour that
will be implemented by differing classes from that hierarchy.

My UI layer could have a form factory, the MVP layer would have an
interactor factory, a presenter factory, a model factory, possibly a view
factory, etc... The business layer could have all sorts of factories,
depending on the nature of the business classes. The data layer could also
have a SQL generator factrory, a connection factory and others.

Google for Design Patterns, Class Factory for examples of whre you could use
a factory.

But *don't* think that you *have* to have a factory in each layer or even at
all. Factories are not essential in an application, unless you really have a
need for them.

Joanna
 
|> The same layer as the object it is designed to create. Put it anywhere
| > else will introduce unnecessary coupling between layers.
|
| So, should I have a factory in each layer (if needed), like this:
|
| FactoryDA.cs
| FactoryBL.cs
| FactoryUI.cs

Not strictly, no. The Class Factory design pattern can be used for many
different purposes.

And those purposes can vary within a layer?
There is no relationship between factories and layers, a class factory is
related to a given class hierarchy where you define abstract behaviour
that
will be implemented by differing classes from that hierarchy.

So it would be more appropriate to designate factories according to purpose:

in the DA layer:
FactoryDataset
FactoryDataTable

in the BL layer:
FactorySomeObject
FactorySomeOtherObject

in the UI layer:
FactorySomeControl
FactorySomeForm

Is this correct?
 
"deko" <[email protected]> a écrit dans le message de (e-mail address removed)...

| And those purposes can vary within a layer?

Certainly

| So it would be more appropriate to designate factories according to
purpose:
|
| in the DA layer:
| FactoryDataset
| FactoryDataTable
|
| in the BL layer:
| FactorySomeObject
| FactorySomeOtherObject
|
| in the UI layer:
| FactorySomeControl
| FactorySomeForm
|
| Is this correct?

Yes, but don't fall into the trap of creating factories just because you
can. They are only really suitable for situations where you have a defined
hierarchy that is intended to be used in a polymorphic way from an abstract
or virtual base class.

If you don't have such hierarchies, then don't try to use class factories.
And don't try to design hierarchies just so that you can create a factory
:-)

Joanna
 
| So it would be more appropriate to designate factories according to
purpose:
|
| in the DA layer:
| FactoryDataset
| FactoryDataTable
|
| in the BL layer:
| FactorySomeObject
| FactorySomeOtherObject
|
| in the UI layer:
| FactorySomeControl
| FactorySomeForm
|
| Is this correct?

They are only really suitable for

rather, best suited for
situations where you have a defined
hierarchy that is intended to be used in a polymorphic way from an
abstract
or virtual base class.

If you don't have such hierarchies, then don't try to use class factories.
And don't try to design hierarchies just so that you can create a factory

I am intent on using a factory class, and will kill anyone that gets in my
way.
 
"deko" <[email protected]> a écrit dans le message de (e-mail address removed)...

| rather, best suited for

furry nuff.

| I am intent on using a factory class, and will kill anyone that gets in my
| way.

Then don't let me stand in your way :-)

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top