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 7671803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:08:30+00:00 2026-05-31T16:08:30+00:00

This is a design problem I am facing. Let’s say I have a cars

  • 0

This is a design problem I am facing. Let’s say I have a cars website. Cars have the following attributes with different possible values.

  • Color: red, green, blue
  • Size: small, big

Based on those attributes I want to classify between cars for young people, cars for middle aged people and cars for elder people, with the following criteria:

  • Cars_young: red or green
  • Cars_middle_age: blue and big
  • Cars_elder: blue and small

I’ll call this criteria target

I have a table cars with columns: id, color and size.

I need to be able to:

a) when retrieving a car by id, tell its target (if it’s young, middle age or elder people)

b) be able to query the database to know how many views had cars belonging to each target

Also, as a developer, I must implement it in a way that those criteria are easily changed.

Which is the best way to implement it? Is there a design pattern for it? I can explain two possible solutions I thought about but I don’t really like:

1) create a new column in the database table called target, so it’s easy to make both a) and b).

Drawbacks: Each time crieteria changes I have to update the column target for all cars, and also, I have to change the insertNewCar() function.

2) Implement it in the ‘Cars’ class.

Drawback: Each time criteria changes I have to change query in b) as well as code in ‘getCarById’ in a).

3) Use TRIGGERS in SQL, but I would like to avoid this solution if possible

I would like to be able have this criteria definition somewhere in the code which can be changed easily, and would also hopefully be used by ‘Cars’ class. I’m thinking about some singleton or global objects for ‘target’ which can be injected in some Cars methods.

Anyone can explain a nice solution or send documentation about some post that faces this problem, or a pattern design that solves it?

  • 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-31T16:08:31+00:00Added an answer on May 31, 2026 at 4:08 pm

    On first sight specification pattern might meet your expectations. Wikipedia gives a nice explanation how it works, small teaser bellow:

    OverDueSpecification OverDue = new OverDueSpecification();
    NoticeSentSpecification NoticeSent = new NoticeSentSpecification();
    InCollectionSpecification InCollection = new InCollectionSpecification();
    
    ISpecification SendToCollection = OverDue.And(NoticeSent).And(InCollection.Not());
    
    InvoiceCollection = Service.GetInvoices();
    
    foreach (Invoice currentInvoice in InvoiceCollection) {
        if (SendToCollection.IsSatisfiedBy(currentInvoice))  {
            currentInvoice.SendToCollection();
        }
    }
    

    You can consider combine specification pattern with observers.

    Also there are few other ideas:

    • extention of specification pattern on SQL generation, WHERE clauses in particular
    • storing criteria configuration in database
    • criteria versioning: storing information about version of rules used to assign to category comined with category itself
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is design problem. Let's assume that we have this kind of model in
I'm making the design of a OO framework and I'm facing the following problem.
I'm facing a problem which is probably extremely common in game-design. Let's assume that
There is a design problem like this. Suppose you have a set of class
I keep running into this design problem, and I'm not happy with my solution
This is a Ruby design problem. How can I make a reusable flat file
I am thinking about a DB Design Problem. For example, I am designing this
I'm using Glade-3 for my GUI design, but I keep hitting this problem. I
I have this design which I cannot seem to get right, I would like
I have tough time making this design decision. I could go with traditional new

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.