O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring with Microsoft Visual Studio 2010

Book Description

This book is a superb practical guide for any developer considering refactoring their code with Visual Studio. Its accessible approach covers all aspects of updating your C# code base to make it maintainable and adaptable.

  • Make your code base maintainable with refactoring

  • Support new features more easily by making your system adaptable

  • Enhance your system with an improved object-oriented design and increased encapsulation and componentization

  • Concepts are presented in a comfortable one-on-one, pair-programming style

  • A practical approach that's packed with examples to enrich understanding

  • In Detail

    Changes to design are an everyday task for many people involved in a software project. Refactoring recognizes this reality and systematizes the distinct process of modifying design and structure without affecting the external behavior of the system. As you consider the benefits of refactoring, you will need this complete guide to steer you through the process of refactoring your code for optimum results.

    This book will show you how to make your code base more maintainable by detailing various refactorings. Visual Studio includes some basic refactorings that can be used independently or in conjunction to make complex refactorings easier and more approachable. This book will discuss large-scale code management, which typically calls for refactoring. To do this, we will use enterprise editions of Visual Studio, which incorporate features like Application Performance Explorer and Visual Studio Analyzer. These features make it simple to handle code and prove helpful for refactoring quickly.

    This book introduces you to improving a software system's design through refactoring. It begins with simple refactoring and works its way through complex refactoring. You will learn how to change the design of your software system and how to prioritize refactorings—including how to use various Visual Studio features to focus and prioritize design changes. The book also covers how to ensure quality in the light of seemingly drastic changes to a software system. You will also be able to apply standard established principles and patterns as part of the refactoring effort with the help of this book. You will be able to support your evolving code base by refactoring architectural behavior. As an end result, you will have an adaptable system with improved code readability, maintainability, and navigability.

    Refactor Visual Studio solutions to make them more maintainable

    Table of Contents

    1. Refactoring with Microsoft Visual Studio 2010
      1. Refactoring with Microsoft Visual Studio 2010
      2. Credits
      3. About the Author
      4. Acknowledgement
      5. About the Reviewers
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Introduction to Refactoring
        1. What is refactoring?
        2. Why the term refactoring?
        3. Unit testing the second half of the equation
        4. Simple refactoring
        5. Technical debt
        6. In the software development trenches
        7. The option of rewriting
        8. Working refactoring into the process
        9. What to refactor
          1. Refactoring to patterns
          2. Refactoring to principles
          3. Code smells
          4. Complexity
          5. Performance
          6. Kernel
          7. Design methodologies
          8. Unused and highly-used code
        10. Refactoring in Visual Studio® 2010
          1. Static code analysis
          2. Code metrics
        11. Summary
      8. 2. Improving Code Readability
        1. Built-in Visual Studio® refactorings
          1. Rename identifier refactoring
            1. Rename field
            2. Rename property
            3. Rename method
            4. Rename local variable
            5. Rename class
          2. Extract Method refactoring
          3. Encapsulate Field refactoring
        2. The smell of code
          1. Duplicate code smell
            1. Duplicate code in a class
            2. Duplicate code in multiple classes
            3. Duplicate code in construction
            4. Advanced duplicate code refactoring
          2. Long method smell
          3. Code comments smell
        3. Dead code
        4. Intention-revealing design
        5. You ain't gonna need it
        6. KISS principle
        7. Keeping track of code changes
        8. Check-in often
        9. Removing unused references
        10. Summary
      9. 3. Improving Code Maintainability
        1. Code maintainability
          1. Automated unit testing
          2. Feature Envy code smell
          3. Design for the sake of reuse
          4. Don't repeat yourself
          5. Inappropriate Intimacy code smell
          6. Lazy Class code smell
          7. Improved object-model usability
          8. Contrived Complexity
          9. Detecting maintainability issues
        2. Summary
      10. 4. Improving Code Navigation
        1. Navigating object-oriented code
        2. Convention over Configuration
          1. Consistency
          2. Conventions
            1. Naming
          3. Scoping types with namespaces
        3. IDE navigation
          1. Search
          2. Class View
          3. Solution Explorer
          4. Class Diagram
          5. Code Editor
        4. Navigation with design patterns and principles
        5. Summary
      11. 5. Improving Design Correctness
        1. Liskov substitution principle
          1. Convert to Sibling refactoring
          2. Refactoring to single class
        2. Composition over inheritance
          1. Refactoring virtual methods to events
          2. Exceptions to preferring composition
          3. Replace inheritance with delegation refactoring
        3. Object-oriented design and object behavior
          1. Refactoring to improved object-orientation
        4. Move initialization to declaration
          1. Value types
          2. Refactoring to value type
          3. Modeling business rules appropriately
        5. Summary
      12. 6. Improving Class Quality
        1. Cohesion
          1. Class cohesion
            1. The Single Responsibility Principle
            2. Refactoring classes with low-cohesion
            3. Detecting classes with low-cohesion
          2. Method cohesion
            1. Refactoring methods with low-cohesion
          3. Namespace cohesion
            1. Refactoring namespaces with low-cohesion
          4. Assembly cohesion
            1. Refactoring assemblies
        2. Coupling
          1. Refactoring subclass coupling
          2. Refactoring content coupling
            1. Interface-based design
            2. Delegates
            3. Events
          3. Refactoring external coupling
          4. Dependency cycles
          5. Proper dependency design
        3. Summary
      13. 7. Refactoring to Loosely Coupled
        1. What is loosely coupled?
          1. What are coupling and dependencies?
            1. Tightly-coupled
        2. Dependency Inversion principle
        3. Inversion of Control
        4. Dependency Injection
        5. Working with IoC containers
          1. Tightly coupled to creation
          2. Factory Pattern
          3. Abstract Factory
        6. Decorator pattern
        7. Detecting highly-coupled
        8. Types of coupling
          1. Afferent coupling
          2. Efferent coupling
        9. Interface segregation principle
        10. Drawbacks of loosely-coupled
        11. Other methods of loose-coupling
          1. Web services
          2. Communication hosts
        12. Summary
      14. 8. Refactoring to Layers
        1. Layers
          1. Business logic and domain layers
          2. Data Access Layers
            1. Refactoring UI data access to Data Access Layer
            2. Refactoring domain data access to Data Access Layer
          3. Plain Old CLR Objects
          4. User interface layers
        2. Model View Presenter (MVP)
        3. Additional layers
        4. Summary
      15. 9. Improving Architectural Behavior
        1. Behavioral patterns
          1. Don't Repeat Yourself (DRY)
          2. Strategy pattern
          3. Detecting need for strategy pattern
          4. Refactoring to strategy pattern
          5. Specification pattern
          6. Detecting need for specification pattern
          7. Refactoring to specification pattern
          8. Publish/Subscribe paradigm
          9. Observer pattern
          10. Detecting the need for the observer pattern
          11. Refactoring to the observer pattern
        2. Summary
      16. 10. Improving Architectural Structure
        1. Structural patterns
          1. Legacy code
          2. Adapter pattern
            1. Detecting need for the adapter pattern
            2. Refactoring to the adapter pattern
          3. Façade pattern
            1. Detecting the need for façade
            2. Refactoring to the façade pattern
          4. Proxy pattern
            1. Detecting need for proxy
            2. Refactoring to proxy
        2. Object/Relational Mapping
          1. Problems with code generation
          2. Detecting need to refactor to ORM
          3. Refactoring to ORM
            1. ORM sessions
        3. Summary
      17. 11. Ensuring Quality with Unit Testing
        1. Change is not always good
        2. Automated testing
        3. Unit tests
          1. Other testing
          2. Mocking
          3. Priorities
          4. Code coverage
        4. Mocking frameworks
          1. Rhino Mocks
          2. Moq
        5. Unit testing existing legacy code
          1. TypeMock isolator
        6. Unit testing in Visual Studio®
        7. Test driven development
        8. Unit testing frameworks
          1. NUnit
          2. XUnit
        9. Automating unit-testing
          1. Continuous Integration
        10. Third party refactoring tools
          1. Resharper
          2. Refactor! Pro
        11. Summary