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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:42:52+00:00 2026-06-02T05:42:52+00:00

Consider this class diagram: +——–+ * +——————+ * afraid-of +————+ | Garden |——>| Animal

  • 0

Consider this class diagram:

 +--------+     * +------------------+ * afraid-of             +------------+
 | Garden |------>|    Animal        |<------------------------| Baby       |
 +--------+       +------------------+                         +------------+
                        ^
                        |
                 +----------+------+
                 |                 |
          +------+------+   +------+-----+
          | Cat         |   | Wolf       |
          +-------------+   +------------+

Animal has two roles:

  1. They will be walking around the garden (Class Instance)
  2. The baby is afraid of some animals (Class Type)

What baby should keep? One instance of each animal it’s afraid of? (sounds like poor design)
The type name? (I always try to avoid refactoring)

How should this be solved? (I’m using C# and I mention it only at the end because I hope there is a general, language-free design pattern or idea here)

Thanks

  • 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-02T05:42:55+00:00Added an answer on June 2, 2026 at 5:42 am

    If babies are always afraid of the same animals, you don’t have to keep anything.
    You can have a method:

    public bool IsAfraid(Animal animal)
    {
        return animal is Wolf;
    }
    

    If babies are afraid of different animals in different places and times, you should make every animal have a property AnimalType (flag enum). The baby will then have a property AfraidOf, of type AnimalType.
    And then, checking if you are afraid of an animal is simple:

    bool afraid = this.AfraidOf.HasFlag(animal.AnimalType);
    

    Finally, you should probably have different types of linking to different classes for different types of relationships in your schema (Contains, Inherits, Afraid of).

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

Sidebar

Related Questions

Consider this class diagram: Car has a constant max speed of 200 kph, and
Consider this menu output by a WordPress function: <ul id=header-cats> <li class=cat-item cat-item-6><a href=url
Consider this simple class: package Foo; use Moose; has foo => ( is =>
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there
Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
Consider this class: class test { public function __set($n, $v) { echo __set() called\n;
Consider this sample class, class TargetClass { private static String SENSITIVE_DATA = sw0rdfish; private
Consider this code : class MyClass<T> { } class AnotherClass : MyClass<String> { }
Let's consider this model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time =
Consider this - a base class A, class B inheriting from A, class C

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.