Question

For questions 1-5, each block of pseudocode violates 1 of the S SOLID principles. Without repeating a princip you would address fixing the violation. le (use each one exactly once), choose a SOLID principle that is violated. Describe in detail how
3- (5 pts) class Bear public: enum class Food (Berries, Honey, Fish): void eat (Food food): class Grizzly: public Bear /I A dangerous wild animal. class Teddy: public Bear // A toy named after the 26th President of the U.S. class Chicago: public Bear // An NEL football team. 4-(5 pts) class Polygon double width( 0.0 double height 0.0 public: void set (double const width, double const height) double get_area) return width height: virtual double get_perimeter () const 0 li class Triangle: public Polygont// TODO: Define for const objects too.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Liskov Substitution Principal (LSP) is violated.

LSP says that the object of a derived class should be able to replace an object of the base class without bringing any error in the system or modifying the behavior of the base class.

So as to the principle we should be able to replace a Bear object by any object of Grizzy ,Teddy or Chicago without bringing any error.

As per polymorphism rule all the derived class may define its own function definition for the function eat(), so it can produce an error if we want to do the replacement of the Bear object by any Derived class object.

so it can be fixed by using an interface to have the function declaration eat() , like

interface eating {

void eat(Food);

}

now each derived class can implement this interface defining its own definition for that function eat().

class Teddy : eating

{

void eat(Food)

{

//

}

}

class Grizzy : eating

{

void eat(Food)

{

//

}

}

class Chicago : eating

{

void eat(Food)

{

//

}

}

OR

we may define the base class Bear as an abstract class as it is not defining the function eat() and it will prevent the object creation of the class Bear ,declare the function eat() as an abstract also, like

abstract class Bear

{//

abstract void eat(Food);

}

Add a comment
Know the answer?
Add Answer to:
For questions 1-5, each block of pseudocode violates 1 of the S SOLID principles. Without repeating...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT