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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:56:58+00:00 2026-06-01T14:56:58+00:00

I have to produce a class diagram for a condition, condition was something like:

  • 0

I have to produce a class diagram for a condition, condition was something like:

Fruits have colors and fruits can grow. Apples are fruits.
They have seeds. Seeds can make new apples.

I would like to have some experts advice before I implement any design.

I was thinking some thing like this but I am no expert so please help me out here

abstract class Fruit
{
    protected $_color;

    abstract function grow();

    protected function seed(Fruit $fruit)
    {
        return $fruit;
    }
}

class Apple extends Fruit
{

}

How can this be achieved using composition or inheritance ?

  • 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-01T14:57:00+00:00Added an answer on June 1, 2026 at 2:57 pm

    There are fruits that have seeds. Apple is one of those fruits. So I would use a simple plain inheritance design:

    abstract class Fruit
    {
         private $color;
    
         public function getColor(){/* */};
         public function setColor($color){/* */}
    
         abstract public function grow();
    }
    
    abstract class SeedableFruit extends Fruit
    {
        public function seed()
        {
            //Do something
        }
    }
    
    class Apple extends SeedableFruit
    {
        public function grow()
        {
            //Do something
        }
    }
    

    In this way you cannot reuse the implementation of the grow method of a non-SeedableFruit in a Fruit with seeds, but if you think how natural evolution works, it makes sense… because in that case the two fruits have a common ancestor that grows in the same way, so the problem could be resolved inserting that common ancestor in the class hierarchy.

    The alternative design was to use a DecoratorPattern to describe a fruit that can have seeds, and then create an Apple with seeds with a call like new SeedableFruitDecorator(new Apple());. But I think it’s not the correct way, since an Apple has always seeds.

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

Sidebar

Related Questions

I have implemented an HTTPOperations class in Android that can successfully produce an HTTP
I have something like this: class Base { public: static int Lolz() { return
I have a class: MessageReceiver.java that receives messages but can also produce messages indirectly
GenoTipController must produce class according to the enum type. i have 3 class: _Company,_Muayene,_Radyoloji.
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have a class where I like to initialize my var by reading a
I have seen many php scripts in which you can cascade class method to
Hello I have a class like so class myclass { public string string1; public
I noticed that new versions of doxygen (I have 1.8.1.1) produce class lists where
I have data in database like this id class gender 1 A F 2

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.