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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:54:39+00:00 2026-05-18T06:54:39+00:00

I use C# to write a (hypothetical) application – online store. I have a

  • 0

I use C# to write a (hypothetical) application – online store.

I have a database of products, each product has following information associated with it:

  • Product Number (required)
  • Name (required)
  • Price (required)
  • Rating (optional)
  • Sold Quantity (optional) — this is total sale of this product

I have 4 pages that show filtered list of products. Pages show different information for each product:

  • 1st page : PN, Name, Price
  • 2nd page : PN, Name, Price, Rating
  • 3d page : PN, Name, Price, Sold Quantity
  • 4th page : PN, Name, Price, Rating, Sold Quantity

My question is, how do I design data structures to accommodate all my pages with little duplication?

Brute force approach is to create a type for each page:

IList<Product>
IList<ProductWithRating>
IList<ProductWithSoldQuantity>
IList<ProductWithRatingAndSoldQuantity>

later 3 can derive from Product but due to lack of multiple inheritance ProductWithRatingAndSoldQuantity can’t derive from both Rating and SoldQuantity products.

In a dynamic language I would just add whatever fields I need and be happy.

So I could simulate a dynamic-language-approach by storing extra information (rating, sold quantities) in separate dictonaries, e.g.:

{
    IList<Product> Products;
    IDictionary<Product, Rating> ProductRatings;
    IDictionary<Product, SoldQuantity> ProductSoldQuantities;
}
// is equivalent to
IList<ProductWithRatingAndSoldQuantities>

Building a Product structure that includes everything and then pass around a partially initialized object is not a solution I am looking for.

Any suggestions?

  • 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-18T06:54:39+00:00Added an answer on May 18, 2026 at 6:54 am

    Sorry not enough chars to reply in comment.

    You should have a single domain object, Product. It would have non-nullable Name and ProductNumber and Price, because you cannot have products that don’t have those things.

    Rating should be a nullable, because it is possible to have a Product that does not have a rating. Whether or not a Product has a Rating, it is still always a Product. I’ll leave QuantitySold, because I wouldn’t actually store that as a property of product, I would have Orders and OrderLine collections, and calculate QuantitySold from those (normalisation). However in the absence of those other collections, you could store it as a field on Product. If I was going to do that, it would be a non-nullable integer property, the default being zero.

    You only need a single collection to filter, which would be some implementation of IEnumerable or IQueryable or both, most likely you would opt for something like Entity Framework and actually have an ObjectSet but I’d try to keep my design agnostic of what storage method I’m using and work against those interfaces.

    You can then query your single collection to identify which attributes are null on the Products in your domain model. Syntax might not be perfect, but nothing Intellisense won’t pick up, I’m a VB guy 99% of the time.

    var productsWithNoSales = Context.Products.Where(p=> p.QuantitySold == 0);
    var productsWithNoRating = Context.Products.Where(p=> p.Rating == nothing);
    var productsWithNoSalesOrRating = Context.Products.Where(p=> p.QuantitySold == 0).Where(p=> p.Rating == nothing);
    

    That is pretty much the cleanest possible domain model for what you are after.

    Inheritance would be if you had specialised derivatives of Product that have either extra properties or different behaviour. For example, my own system has a base Product class, and a EbayProduct and AmazonProduct entity which both inherit from Product and contain only the extra logic and properties associated with working with those sites. My Product class has about 20 properties – mostly nullable, as when we list products we don’t necessarily have all the information available. Of these 20, the most I display on any one page is about 15. I probably do something similar to what you are trying to do in that I filter out Products that aren’t ready to list yet using the exact method described, i.e. filtering my Products collection for missing fields.

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

Sidebar

Related Questions

I use NumericField write a Integer in lucene Index: doc.add( new NumericField(id,Integer.MAX_VALUE,Field.Store.YES,true) .setIntValue(123) );
I have to use write a program in which the dictionary should be used
I'm doing a platform independent PyQt application. I intend to use write a setup.py
a conceptual question: I have a global system which sales agents use to write
I've just realized that when I use write.table() for saving a data frame in
Possible Duplicate: Why use document.write? Considering the negative effects of document.write(), why are most
The logged value is shown below: but why when I use document.write or alert
I use Eclipse to write Java code and use DropBox to sync my code
I use Aptana to write Python code. Aptana often report error due to the
When I use fputcsv to write out a line to an open file handle,

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.