Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading content…
Transcript

Open - Close

Principle

Example

Minor Improvement

Create Sub-Classes

Create Interface

Optional

Agenda

Open for extension

  • You can add new behavior without modifying the existing code

  • When new requirements are added, existing code doesn’t need to be modified

  • What - is Open/ Closed Principle?

  • Why - is it important?

  • Code smells - how do we encounter it day to day?

  • Anti-patterns - what common patterns do we see in legacy code that violate this principle?

  • How - do we implement in our code?

Closed for modification

  • Extending functionality doesn’t require changing existing functionality

  • Consumers of existing functionality don’t have to change for the new functionality

Code Smells

What

  • Tight Coupling
  • If I make a change to one of my classes, how many other things have to be aware of that change?
  • Am I depending on a concretion instead of an abstraction when it should be the inverse?
  • Duplication
  • Do I see the same code repeated with small changes?
  • Do I see the same structure repeated across classes or layers?

  • Software entities should be open for extension

  • Software entities should be closed for modification

Anti-patterns

Why

  • God Object – too many bits of functionality in a single component
  • Shotgun Surgery – one feature forces many changes across the entire solution
  • Hard code – embedding environment assumptions in the project
  • Repeating Yourself – see Repeating Yourself
  • Peeking behind the veil – examining what concrete class is implementing the interface
  • The surface area of code changes becomes drastically minimized

  • The core approach for implementing polymorphism

  • Facilitates implementation across team members and reduces incidental complexity

  • Design solutions to be left alone when completed

Image by Tom Mooring

Learn more about creating dynamic, engaging presentations with Prezi