Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:18:55+00:00 2026-05-16T15:18:55+00:00

I’m not really sure to understand completely the factory pattern. Let’s say I have

  • 0

I’m not really sure to understand completely the factory pattern.

Let’s say I have a class Customer which has basically the following methods:

  • CreateCustomer – static, creates a customer from scratch and adds it to the database,
  • LoadCustomer – static, loads an instance of a Customer from the database,
  • KillCustomer – not static, removes a customer from the database.

If I understand well,

  1. LoadCustomer is a good candidate to be put into a factory class.
  2. What about CreateCustomer? I suppose that it may be put into a factory class. Is that right? If not, the static CreateCustomer method will change the database state, then call CustomerFactory.LoadCustomer. IMHO, this is bad design: a given object don’t have to know anything about her own factory.
  3. KillCustomer seems to me a very bad candidate for a factory: it acts on an already created object, rather than creating one. On the other hand:
    • If a non-static method removes the customer from the database, the object (from which KillCustomer was called) still exists. This is quite strange to see an object committing suicide on database level and still remaining on business level. Calling KillCustomer from factory would be more reasonable on this level. For example, if the object is cached in application, the factory may remove it both from database and from cache.
    • Putting in different classes the method which creates an object and the method which removes it seems strange too. Why can factory just build something, and never destroy what was built?

Last but not least, let’s say customers are cached in application. Who is responsible to manage cache? IMO, the factory must do it: it creates the objects, so it is a good candidate to choose if a new object with properties populated from database must be loaded, or if the object already exists in cache.

So, what’s right and what’s wrong in what I’m thinking about factory pattern?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:18:56+00:00Added an answer on May 16, 2026 at 3:18 pm

    Factory is not for building things. It’s for building things when you don’t know exactly what you’re going to build. In my opinion, all of your methods are poor candidates for a factory.

    Now, if you had a whole big bunch of different kinds of customers in an inheritance hierarchy rooted at Customer and some details about the data used to create a customer determined which kind of customer was made, then CreateCustomer would be a great candidate for a factory method. The same with LoadCustomer since presumably you aren’t completely sure exactly which sort of customer is being stored in the database.

    But KillCustomer is still a bad candidate. And that’s because it should just be a virtual method. Then it knows exactly which kind of customer it was called on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a JSP page retrieving data and when single or double quotes are
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.