Category Archives: week1

From Inheritance to Strategy: Lessons from the Duck Simulator

One of the primary obstacles in software design is ensuring that code remains easy to maintain and extend. Initially, inheritance seems like the clear answerplacing shared code in a superclass and allowing subclasses to override as necessary. However, as demonstrated in the classic Duck Simulator example, relying solely on inheritance can result in fragile designs.

From Inheritance to Strategy

In the first version of the Duck Simulator, all ducks derived from a base Duck class. This approach worked until we introduced unique ducks like RubberDuck (which squeaks instead of quacking and cannot fly) and DecoyDuck (which does neither). Suddenly, we found ourselves needing to override or disable inherited methods, leading to duplication and design issues such as viscosity and fragility. Transitioning to interfaces helped to declutter the design, but it also required us to replicate code across similar ducks. The true breakthrough arrived with the Strategy Pattern,

We extracted behaviors like flying and quacking into separate classes (FlyWithWings, FlyNoWay, Quack, Squeak, MuteQuack). Now, ducks possess behaviors rather than inheriting them. These behaviors can be altered at runtime, and new ones can be introduced without changing existing code. This transition underscored the principle of favoring composition over inheritance and illustrated the Open-Closed Principle: code is open for extension but closed for modification.

Design Principles in Action

The exercise reinforced several essential principles: High Cohesion: Each behavior class excels at a single task. Low Coupling: Ducks are indifferent to how they fly or quack, only that they can delegate to a behavior. Encapsulate What Varies: Changes in behavior are contained, not dispersed across subclasses. Collectively, these factors enhance the design’s flexibility and maintainability.

UML: Clearly Communicating Design

We also engaged in the practice of illustrating designs through UML diagrams. In contrast to code, UML offers a higher-level representation that clarifies relationships: Associations (for instance, a Student possessing a schedule of Course objects). Multiplicity (for example, a student may enroll in 0–6 courses). Inheritance and interfaces (such as Faculty extending Employee and implementing HasCourseSchedule). Tools like PlantUML enable us to create these diagrams in Markdown, facilitating easy adjustments and sharing.

Key Takeaways

Relying solely on inheritance frequently results in fragile designs. The Strategy Pattern addresses this issue by encapsulating behavior and employing composition. Guiding principles such as High Cohesion, Low Coupling, and Open-Closed promote cleaner designs. UML diagrams provide us with a common language to convey and analyze code. What began as a straightforward duck simulator evolved into an insightful lesson on the significance of design patterns. By embracing the Strategy Pattern and utilizing UML for design modeling, we discovered how to construct systems that are not only functional but also resilient, adaptable, and easy to maintain.

From the blog CS@Worcester – MY_BLOG_ by Serah Matovu and used with permission of the author. All other rights reserved by the author.

Post #1: Tests Adding Value

Have you ever wondered if your tests are adding value to your work? Well I was reading a post by Andy Knight at Automation Panda who talks about the worries of testing and why people may think that it isn’t adding value. Andy begins by talking about how important testing is to software engineering stressing that people make a job out of it so it must be important. He clarifies that testing is important with one word: Bugs. Bug counting though is not the best way to make sure your test are adding value. Andy talks about three main facts that make bug counting not the best way to see if testing is adding value. They are fast feedback, good testing reduces bug count, bug counting drives bad behavior and bugs are usually rare. He goes into detail on all of these and how they effect the value of testing and he has some really good points for all of them. After he establishes why bug counting hurts testing, he goes onto talk about metrics that would be good for testing. He provides three different metrics being: Time to bug discovery, coverage and test failure proportions. He provides reasoning for all those metrics as well.

I don’t know too much about testing, mostly because the class I’m in is going to teach me about testing but this blog post provides a lot of insight on why testing is important and not a waste of time. Testing is a big part of programming as it makes sure that your code doesn’t have too many bugs so it runs as you want it and if it does have bugs, that you find them and able to fix them as soon as possible. I was able to learn that bug counting isn’t the best metric to figure out that your tests are adding value as they have many negative side effects such causing bad behavior or believing that its a waste of time because there are little bugs even though that means its just good code. It is just good to know that there is other metrics that make testing feel more valuable to the software engineering process. After reading about coverage being a metric, it makes a lot of sense why that would be more helpful of a metric than bug counting, covering a wide spread for testing would make it better to find the bugs and makes sure everything is in smoothly. Testing is an important part of software engineering and since it is so important, you want to use the best metrics for it and this blog post provides the best.

Link: https://wordpress.com/read/blogs/122508714/posts/9140

 

From the blog CS@Worcester – Benderson's Blog by Benderson's Blog and used with permission of the author. All other rights reserved by the author.

Intro – CS 448

Hello Everyone in Cs-448  !

My name is Kwame ofori and i am really looking forward to this class and getting some real world experiences. I believe experience is the best teacher so i am ready to learn !

 

 

From the blog CS@Worcester – Le Blog Spot by Abranti3 Dada Kay and used with permission of the author. All other rights reserved by the author.