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

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
 
G

Geoffrey Summerhayes

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
 

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

Top