Service, Factory, etc ... Need advice. Thank You

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

In many C# code examples I see classes that are named Factory or
Service.

For example: ValidationFactory, MailService, etc.

What is the difference?

I usually name Repository to all classes that interact with a
database. For example:
ProductRepository, UsersRepository, etc ...

And then I use Service for other classes that perform some kind of
action like:

MailService > Sends emails, newsletters, etc
FileService > Saves files, for example, after being submitted by
forms, etc

But the Factory is puzzling me ... maybe Factory and Services are the
same thing?

I am just trying to be consistent when creating my C# code.

Thank You,
Miguel
 
Hello,

In many C# code examples I see classes that are named Factory or
Service.

For example: ValidationFactory, MailService, etc.

What is the difference?

I usually name Repository to all classes that interact with a
database. For example:
ProductRepository, UsersRepository, etc ...

And then I use Service for other classes that perform some kind of
action like:

MailService > Sends emails, newsletters, etc
FileService > Saves files, for example, after being submitted by
forms, etc

But the Factory is puzzling me ... maybe Factory and Services are the
same thing?

I am just trying to be consistent when creating my C# code.

By definition a factory makes objects but the factory decides which
class to use.

See http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
and http://en.wikipedia.org/wiki/Abstract_factory_pattern
 
Back
Top