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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:02:55+00:00 2026-05-31T20:02:55+00:00

In his book Java Design , Peter Coad says that one of the five

  • 0

In his book Java Design, Peter Coad says that one of the five criteria a subclass should meet is that the subclass “does not subclass what is merely a utility class (useful functionality you’d like to reuse).” For an example in Java, he says that making one of your domain classes a subclass of the Observable class is a violation of his rule: “Observable is a utility class, a collection of useful methods–nothing more.”

In that context, here are some example test classes patterned after actual tests I’ve written:

class BaseDataGeneratorTestCase (unittest.TestCase):
    def _test_generate_data(self, generator, expected_value):
        # Imagine there's a lot more code here, making it
        # worthwhile to factor this method out.
        assert generator.generate_data() == expected_value

class DataGeneratorTests (BaseDataGeneratorTestCase):
    def test_generate_data(self):
        self._test_generate_data(DataGenerator(), "data")

class VariantDataGeneratorTests (BaseDataGeneratorTestCase):
    def test_generator_data(self):
        self._test_generate_data(VariantDataGenerator(),
                                 "different data")

Though this example is trivial, consider that the real tests and their surrounding system are, of course, much more complex. I think this example is usable as a vehicle to try and clear up some of my confusion about the proper use of inheritance.

Is subclassing BaseDataGeneratorTestCase a bad idea? Does it qualify as just “useful functionality [I’d] like to reuse”? Should _test_generate_data just be a function, not in any class?

  • 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-31T20:02:56+00:00Added an answer on May 31, 2026 at 8:02 pm

    Basically you can solve the problem any way you like. OOP is just a paradigm that’s supposed to help you design things in a clearer and maintainable way.

    So, the question you should ask yourself any time you want to use inheritance they are have they same role, and you just want to add functionality ? or do you want to just use the nice methods in the “base” class ?

    It’s just a matter of concept, and in your little example it could go either way because they have the same concept, but basically, you’re just using the base class as a utility.

    If you want the base class to actually be a base class you should design it so every inherited class will behave the similarly.

    I do agree that conceptually it would make sense to have a unit test baseclass for all the tests that work similarly.

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

Sidebar

Related Questions

Meyers in his book 50 ways to improve... second edition writes that I must
Robert C. Martin in one of his book mention about viscosity as a symptom
In his book Effective Java , Joshua Bloch recommends against using Interfaces to hold
In Brian Goetz's book, Java Concurrency in Practice, his example of a Reentrant lock
I'm learning quicksort from Sedgwick's book. One of his exercise problems is Write a
Scott Meyers in his book Effective C++ says, To disallow functionality automatically provided by
Meyers mentioned in his book Effective C++ that in certain scenarios non-member non-friend functions
In his book High Performance Websites Steve Souders wrote (2007) that browsers limit parallel
This question was asked by Ed Burns in his book 'Riding the Crest'. I
I ran across the following code in Ely Greenfield's SuperImage from his Book component

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.