Thread: OOP Advice

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513

    OOP Advice

    I'm posting this here since I'm currently learning C#, but this is more of an OOP question.

    The program I'm writing will calculate the parallel resistance of two resistors. The user enters a target resistance and percent error, then the program runs through a database of existing resistors, calculates the equivalent resistance of all pairs, and any that fall within the percent error are added to a list. The list is then printed to the user.

    I will have a class Parallel that will perform the calculations and store the resistor-pairs that are valid.

    I'm not sure who should be responsible for adding the resistors to the list. I see two options:

    1. The caller adds the resistors: The caller will call a Test() method in Parallel, and if it return success, the caller will then call an Add() method in Parallel.

    2. Parallel adds the resistors: The caller will simply send all resistor-pairs to Parallel, and Parallel will perform the calculations, determine if they are valid, and add them to the list itself.

    Any thoughts/explanations on which option is better?

  2. #2
    Registered User
    Join Date
    Sep 2022
    Posts
    55
    IMHO, calculating the resulting resistance of all pairs is the most resource intensive process. Depending on whether you allow the user to perform multiple searches, it may make sense to precalculate them once and sort by the result to easily find the matching pairs. This precalculation can be performed during the construction of the class object, where the list of available resistors is passed to initialize it.
    So maybe just store the pre-computed values in the class and have a class method return the list of matching pairs instead of storing them in the object. WDYT?

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I like this approach a lot. Getting the range of acceptable values would then simply be a matter of grabbing a subsection of the pre-computed data.

    I will probably use a Compute() method instead of doing the calculations in the constructor, since there will be options (e.g. resistor size) that the user can change that will effect the results.

    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-12-2020, 06:40 PM
  2. Please Some Advice?
    By Dilmerv in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 10:03 AM
  3. Need advice
    By laasunde in forum C++ Programming
    Replies: 8
    Last Post: 02-10-2003, 10:06 AM
  4. Need advice
    By laasunde in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2002, 11:58 AM
  5. need advice again
    By roslinst in forum C Programming
    Replies: 2
    Last Post: 11-13-2002, 12:18 AM

Tags for this Thread