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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:12:59+00:00 2026-05-13T18:12:59+00:00

I often have the same trouble when I have to design my class for

  • 0

I often have the same trouble when I have to design my class for a web application. The requirements are :
– maintainable (no copy-paste for instance)
– layers fully separated (the business layer doesn’t have to know which method of the data layer is used)
– high performance : don’t load useless data.

First I have a table with all my customers and their addresses :
Code :

Customer
--Id
--Name
--Address
----City
----ZC
----Street

Now I want a table (in another page) with all my customers and the books that they bought, I have a few possibilities :

1/ I create a new class :

Code :

CustomerWithBooks
--Id 
--Name
--Books[]
----ID
----name

PRO : I load only the useful data
CONS : I build my class after my UI , and there is copy-paste.

2/ I add Books[] to the first class.
PRO : Everything is in the same class, it’s maintainable
CONS : I load the address for nothing. If I don’t load the address I can : lazy loading, but I really don’t like it, or when I use my class I have to know which method of my DAL i called, and I don’t like it.

3/ I use inheritance :
Code :

ClientBase
--ID
--Name

ClientWithBooks : ClientBase
--Books[]

ClientWithAdress : ClientBase
--Address

PRO: really maintenable, and I don’t load data for nothing
CONS : What do I do if in one UI I want to show the Books AND the Address ?

4/ ?? I hope there is a perfect solution

  • 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-13T18:12:59+00:00Added an answer on May 13, 2026 at 6:12 pm

    You option 1 is close to good, assuming I understand it correctly. A customer and a book are two completely different things. You want that data/functionality separate, and should not inherit from any common base class (that you have made).

    As the “Con” you say: I build my class after my UI , and there is copy-paste.

    • A. If you mock up some UI to help clarify requirements before you settle on your design and code up classes, that’s good, not bad.
    • B. Good arrangement of your domain objects helps eliminate copy/paste, not cause it. If you have some seemingly repetitive code within your well-arranged classes (often data access code) that’s typical, don’t worry. You can address with with a good data-access layer/tool, good shared logging resources, etc. Repetitive code within your classes just means you have more design improvement to do, not that having separate classes for all your domain realities is bad.

    On the page where you need to deal with both customers and books, you will use customer objects and book objects, and probably a books collection object. And depending on how your db/object-model are set up, you might be dealing with other objects to get form customer to the books they bought. For example, the customers probably buy 1 or more books at the same time, and these are tied to an Order object, which has a reference to a customer. So, you’ll probably go from a

    1. Customer to an
    2. Orders collection containing all of that customers orders to the individual
    3. Order objects and from there to a corresponding
    4. Books collection containing all the
    5. Book objects that relate to that Order object.

    None of these need to inherit from each other. Now, let’s say getting all the books bought by a customer is something you do a lot, and you want to streamline that. You then want to have a Books collection directly off of Customer that gives you that, though the sql queries you use to get those books still goes through Orders in the db. You must start with your object model (and tables behind the scenes) reflecting reality accurately. Even if this give you seemingly many classes, it is more simple in the end. You might end up with some inheritance, you might not.

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

Sidebar

Ask A Question

Stats

  • Questions 314k
  • Answers 314k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use explicit when you would prefer a compiling error. explicit… May 13, 2026 at 11:09 pm
  • Editorial Team
    Editorial Team added an answer You cannot listen for an event outside of the browser… May 13, 2026 at 11:09 pm
  • Editorial Team
    Editorial Team added an answer There is a nice post here that details one way… May 13, 2026 at 11:09 pm

Related Questions

I have a project in which we often use Integer.parseInt() to convert a String
I have always thought it was best practice to be explicit in naming my
I'm working on a small fun projects that builds a robot. We as the
We have written a software package for a particular niche industry. This package has
Is there a way to run a regexp-string replace on the current line in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.