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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:42:59+00:00 2026-06-13T13:42:59+00:00

I am working on a component which is supposed to: receive data (collection of

  • 0

I am working on a component which is supposed to:

  1. receive data (collection of items) from some external calculation component. I expect about 100-1K of items on input on each request.

  2. validate data, calculate some attributes if missing

  3. persist data

There are about ten types of items. I use inheritance to model items. I have a base item class with common attributes and calculations and subclasses implementing type specific problems. Similar to following example:

public abstract class BaseItem {
    String name;
    boolean valid = true;

    public void postCalucate() {
        //common calculation
                    valid = valid && (name != null);
    }
}

public   class ItemA extends BaseItem {
    BigDecimal value;

    @Override
    public void postCalucate() {
        //some A specific calculations                        
        super.postCalucate();
    }
}

public   class ItemA1 extends ItemA {
    BigDecimal extraValue;

    @Override
    public void postCalucate() {
        //some A1 subtype specific calculations
               valid = isA1ItemValid();
        super.postCalucate();
    }
}

public   class ItemB extends BaseItem {
    Integer size;

    @Override
    public void postCalucate() {
        //some B specific calculations
        super.postCalucate();
    }
}

Is there any better way/pattern to do my task? Any advices?

  • 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-06-13T13:43:00+00:00Added an answer on June 13, 2026 at 1:43 pm

    The pattern you are trying to use is fairly sound. In general, I would probably suggest the use of an interface instead of a BaseItem class, since it might not contain that much common functionality.

    In general, most people seem to recommend defining interfaces for your classes to implement. If absolutely you want to share common code in an AbstractClass, I would recommend that class implementing the interface, since this pattern would lend itself to greater extensibility and flexibility in the future.

    As such, you would first begin by defining what an Item is for you. For me, it seems that an Item is three things in your use case: one, it must define the postCalculate() method that will be called on all Items. Second, it must provide an isValid() method. And third, it should also provide a getName() method.

    public interface Item {
        void postCalucate();
        boolean isValid();
        String getName();
    }
    

    Then you would begin implementing your Abstract class. Do this only if it really is necessary to share a codebase between all your items.

    public abstract class BaseItem implements Item {
        String name;
        boolean valid = true;
    
        public void postCalucate() {
            //common calculation
            valid = valid && (name != null);
        }
    
        public boolean isValid() { 
            return valid; 
        }
    
        public String getName() {
            return name;
        }
    }
    

    If BaseItem.postCalculate() is something that will need to be done for all items, this is a good way to do it. If you’re not entirely sure, it might be a good idea instead to define a method somewhere in a Helper or Tool class that performs this common calculation for items, and is called by the postCalculate() methods:

    public class ItemTools {
        public static boolean meetsRequirements(Item item) {
            return item.isValid && item.getName() != null;
        } 
    }
    

    This, many would argue, gives you an easier time as your requirements on BaseItem may change over time.

    Regardless of which route you go there, now you’ll just have to define your actual items:

    public   class ItemA extends BaseItem {
        BigDecimal value;
    
        @Override
        public void postCalucate() {
            //some A specific calculations                        
            super.postCalucate();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on custom component, which will contain combo and displayfield. It's supposed to
i am working on a custom component in Delphi -7 for which i have
I'm working on a Windows Runtime component, written in C#, to wrap some COM
I am working on the memory allocator/snapshotting component of a runtime data flow/model analyzer
I am working on a custom Flex 4 component which is an aggregation of
I'm working with a COM component which exposes a lot of Variant properties, but
Months ago I implemented a component which receives data via UDP-network, deserializes it via
Im working on a pre created joomla component which using the MVC Architecture, My
I am currently working on a specification for a software component which will synchronize
i am working on an application which calls the COM component of a partner's

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.