Slide 1

Slide 1 text

Code smell & Refactoring Mamata Gelanee

Slide 2

Slide 2 text

Code Smell are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality. Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

Slide 3

Slide 3 text

“A code smell is a surface indication that usually corresponds to a deeper problem in the system” - Martin Flower

Slide 4

Slide 4 text

Design Principles Every OO Designer should have follow below design principle, failing to that leads to code smells in your software. Design Principles: - Single Responsibility - Open Close principle - Interface Segregation - Dependency Inversion principle - Liskov Substitution principle

Slide 5

Slide 5 text

Levels of Code smell There are three levels of code smell: 1. Method level 2. Class level 3. Application level

Slide 6

Slide 6 text

Bad smells in a code Long Method - Extract method Long class - Extract Class Long parameter list - Introduce Object parameter Primitive Obsession - Introduce Object parameter Duplicate Code (Don’t Repeat Yourself) - Create Template method

Slide 7

Slide 7 text

Long Parameter List

Slide 8

Slide 8 text

Primitive Obsession

Slide 9

Slide 9 text

Duplicate code

Slide 10

Slide 10 text

Switch statements Replace conditional with polymorphism

Slide 11

Slide 11 text

Oddball Solution Move method or Move class

Slide 12

Slide 12 text

Black sheep Move Method

Slide 13

Slide 13 text

Refused Bequest 1. Throw exceptions 2. Push down method or field

Slide 14

Slide 14 text

Speculative Generality Oh! We might need this feature in future Remedy: - Collapse Hierarchy - Inline class - Remove Parameter

Slide 15

Slide 15 text

Quiz Long class

Slide 16

Slide 16 text

Quiz Long Parameter list

Slide 17

Slide 17 text

Questions?

Slide 18

Slide 18 text

Thanks! Software Engineer, Mastercard Transaction solution pvt. Ltd., Vadodara - Gujarat AndiGeeky @MamataGelanee andigeeky.wordpress.com/ mamatagelanee07