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

  • SEARCH
  • Home
  • 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 3676644
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:07:27+00:00 2026-05-19T03:07:27+00:00

We have a big object graph with lot of properties and behavior in it.

  • 0

We have a big object graph with lot of properties and behavior in it. We are currently revisiting our domain and we are going to go the DDD approach. But we are in need of a suggestion from you experts on how to go about creating Factories for our big domain model.

Problem

We cater to multiple geographies like US, Canada, Spain, Chile, Brazil, UK etc. As it is evident each one of then have differences in addresses, names ((last name, surname 1, surname 2 etc)), phone numbers, national IDs etc. At a high level the domain model looks like this

  1. a Transaction can have multiple
    Subject’s
  2. a Subject has Name,
    Address, TelephoneNumber, NationalID
  3. a Subject can be a ConsumerSubject
    or a BusinessSubject
  4. a ConsumerSubject has a PersonName
    while a BusinessSubject has a
    BusinessName
  5. a Address can be a
    USAddress, UKAddress,
    CanadianAddress, ChileAddress etc
    and the same way there can be
    geography specific subclasses for
    most of the domain objects (where
    applicable)

For every new request we need to create this entire set of objects properly populated in a valid state. We can use the Abstract Factory pattern to have Geography specific factories like USTransactionFactory, CanadianTransactionFactory etc.

Required Suggestion here

How to pass-in the parameters to create these objects. Taking Address as an example

  1. Should we have a createXXXAddress(…) method for
    each geography that takes in city,
    state etc as input arguments?
    This
    means that we need to have
    createUSAddress(…),
    createCanadianAddress(…),
    createChileanAddress(…) etc
  2. OR should we just have one createAddress(Address addr) method
    that just takes Address object and
    let the client create the
    appropriate geography specific
    Address object? E.g
    SpainAddress spain=new SpainAddress();
    spain.setMuniciplaityName(…);

  3. OR should we have a separate AbstractFactory for each of the significant domain objects? For e.g USAddressFactory, UKAddressFactory etc

Required Suggestion here

Is there a necessity to create DTO’s for this? I am thinking just pass the domain to presentation layer but maintain immutability by enforcing read-only view of the domain. For e.g each domain object will implement two interfaces: ReadOnlyAddress, MutableAddress. This was inspired by how joda-time.

Any other suggestions and criticisms are welcome.

  • 1 1 Answer
  • 2 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-19T03:07:27+00:00Added an answer on May 19, 2026 at 3:07 am
    1. Should we have a createXXXAddress(…) method for each geography that takes in city, state etc as input arguments? This means that we need to have createUSAddress(…), createCanadianAddress(…), createChileanAddress(…) etc
    2. OR should we just have one createAddress(Address addr) method that just takes Address object and let the client create the appropriate geography specific Address object?
    3. OR should we have a separate AbstractFactory for each of the significant domain objects? For e.g USAddressFactory, UKAddressFactory etc

    I would definitely not recommend option 1: it would result in binding client code to specific geographies, probably requiring lots of switch/if-else statements scattered all over the place, and code changes in each of those whenever geographies are added/removed – the exact problem polymorphism was meant to resolve.

    I am not quite clear about the exact difference between your options 2 and 3, but my first approach would be to use some sort of a GeographyFactory to produce part(s) or the whole of the object graph you describe here. Thus clients would call a single createAddress method but the methodf itself would be polymorphic.

    Whether the factory would be dependency injected directly to the client or used (partly) transparently in the background similar to a locale in C++ depends on the circumstances – both approach may be fine.

    Is there a necessity to create DTO’s for this? I am thinking just pass the domain to presentation layer but maintain immutability by enforcing read-only view of the domain.

    With regards to addresses, I would try to get away by immutable objects only – if an address changes, you can just create a new object and throw away the old one. Note that addresses are rarely first-class entities, but rather surrogate value objects (i.e. have no identity of their own). But of course, a lot depends on the details of your object-relational mapping solution and the DB schema.

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

Sidebar

Related Questions

I have the next problem: I have a big object graph being binary serialized
Suppose I have a big object that contains the properties I require and additionally
This is a C# problem. I have a big object in memory at a
I have been trying to serialize a pretty big object. This object uses dictionaries
I have an object graph that I need to serialize to xml and save
I have this big object that I'd like to fadeOut and its not working
I have a big object say MyApplicationContext which keeps information about MyApplication such as
If my domain object should contain string properties in 2 languages, should I create
I have a big object in memory which I want to save as a
Ok I have a big JS object that contains data I need within 3

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.