Category Archives: Object Oriented Programming

Refactoring Video Tutorial

Code Refactoring Video TutorialAfter you learn the core syntax of a language many programmers are lost on what to learn next. What do you need to know to create large flexible and extendable applications?

I did my best to teach you how to structure your programs in my Object Oriented Design Tutorial. And, to understand OOD you have to understand UML. Then we walked down the path laid by the programming masters when we looked at Design Patterns. That left me with the final part of writing great code, which is my refactoring video tutorial. Continue reading Refactoring Video Tutorial

Code Refactoring 18

Abstract Factory PatternIn this tutorial I end my Code Refactoring Tutorial. It was a big one and between it and my Design Patterns Video Tutorial you should be able to do most anything.

To end this tutorial, I’ll cover the Abstract Factory Pattern again to make sure you understand it. It is often considered a hard to understand pattern, but I’m sure you’ll get it after this video. The code that follows will help explain anything you miss in the video. Continue reading Code Refactoring 18

Code Refactoring 17

Visitor Design PatternIn this part of the code refactoring tutorial I will answer another challenge I recently received. This tutorial is all about the Visitor Design Pattern.

You use the visitor design pattern when you want to perform a similar calculation on many different objects. It seems to confuse people, but I hope to solve that here. If you understand the concept of method overloading and the passing of objects back and forth for data access I don’t think you’ll have a problem. The code that follows should answer any questions you have. Continue reading Code Refactoring 17

Code Refactoring 16

Replace Embellishment to DecoratorIn this tutorial, I’ll answer a question that was sent to me. The question pertains to how can we add additional features to code the right way.

When new features are needed it is a bad idea to add new code to older classes. This makes compact easy to understand classes complicated because they break the Single responsibility principle. I’ll show you here how the decorator design pattern instead places each special case behavior (Embellishment) into its own class.

This is a fabulous pattern. The code below will help you learn from the video. Continue reading Code Refactoring 16

Code Refactoring 15

Replace Primitive Type with a ClassIn this part of my code refactoring tutorial, we’ll look at how to replace a primitive type with a class.

Type safety is very important! So, what we want to do is to eliminate all operations on values that are not of the appropriate data type by protecting the program from bad input. One way we can do this is by replacing primitive types with classes. I’ll walk you step-by-step through the process. The code below will help you along. Continue reading Code Refactoring 15

Code Refactoring 14

Code Refactoring Adapter PatternIn this part of the code refactoring tutorial, I’ll show you how and when to use the Adapter Design Pattern.

With the adapter pattern we can create a new class without disturbing any other code. On top of that adapters make it easier to swap in code at runtime. They also allow you to communicate with code using method names that make sense to you.

I refactor code sent in by one of you and show you how to add a ton of flexibility. The code is below to help you learn. Continue reading Code Refactoring 14

Code Refactoring 13

Replace Conditional with CommandIn this part of my code refactoring tutorial, I’ll show you how to replace conditionals with the command pattern. I’m also going to do more though.

I’ll also review what the command pattern is. I’ll give an example of when you should use it. We’ll look at how to add flexibility with it. I’ll answer your questions based on the refactoring to patterns book. And, we’ll look at how to store commands in an ArrayList. If you need more look at my Command Design Pattern Tutorial and the code below. Continue reading Code Refactoring 13

Code Refactoring 12

Move Accumulation to Collecting ParameterIn this code refactoring tutorial, I’ll show you how to eliminate large Accumulation Methods by Extracting Methods and Using a Collecting Parameter. It sounds complicated but it isn’t!

This tutorial will show you another way to make your code more readable. It will also introduce you to a few jargon terms you will need to know for the future. This video is shorter than normal to focus on topics you need to understand. The code below will help you master this topic.

Continue reading Code Refactoring 12

Code Refactoring 11

Code Refactoring 11One of you guys sent me a request to explain the chapter in Refactoring to Patterns titled Encapsulate Composite with Builder. We will build a table structure (composite) using the Builder design pattern.

I’ll expand the capabilities of the code from this great book to allow us to more easily traverse the tree structure. This will allow us to add children, siblings and item information using a HashMap. This is a beautiful refactoring. All of the code can be found below to help you learn it. Continue reading Code Refactoring 11

Code Refactoring 10

Builder Design PatternIn this part of the code refactoring tutorial I’m going to revisit the Builder Design Pattern for a couple of reasons. First, I receive a bunch of questions about it. Secondly, in the next tutorial I’ll show you how to build composites, which were covered in the last part of the code refactoring tutorial, with the builder pattern.

The builder pattern allows you to build complex objects in a series of steps. In the video and code below, we will build sandwiches. Here is he previous tutorial on the Builder Design Pattern to help as well. Continue reading Code Refactoring 10

Code Refactoring 9

Code Refactoring 9In this part of my code refactoring tutorial I will cover how to turn an implied tree structure into a composite pattern.

What do you do when you want to model a tree structure? You can either list the info as primitives and then search through them for what you want or you can create objects that represent each level of the tree with the composite pattern.

I have an additional composite design pattern tutorial here. The code follows to help you learn. Continue reading Code Refactoring 9

Code Refactoring 8

Code Refactoring 8In this part of my code refactoring tutorial, I’ll show you how to eliminate duplicate code using the template method pattern. If you want to see another example of the template method pattern, I cover it here as well Template Method Design Pattern.

When objects perform similar steps in the same order, that is a sign that a template method is needed. To use it implement the similar code in a template method and allow subclasses to override the behavior that varies.

The video and the code below cover all that you need to know.

Continue reading Code Refactoring 8

Code Refactoring 7

strategy design pattern in javaIn this tutorial we’ll work with the strategy design pattern in java. If you want to learn more, check out my strategy design pattern tutorial after this.

We’ll explore how the strategy pattern can be used to eliminate conditionals during code refactoring. We’ll also see how it can make your code more dynamic and flexible. It is a wonderful pattern!

I also revisit your questions about the guard clause and the code is available below. Continue reading Code Refactoring 7

Code Refactoring 6

Code Refactoring 6In this part of the Code Refactoring tutorial I’ll focus on conditionals. Conditional statements can very often make your code very hard to read.

Here we’ll clean up conditional statements by extracting them into methods. We’ll look at how important naming can be to writing understandable code. We’ll take a look at guard clauses and when to use them. Then we’ll see how polymorphism can eliminate conditionals all together.

The code follows the video, to help you learn. Continue reading Code Refactoring 6

Code Refactoring 5

Replace Constructor with Factory MethodIn this part of the code refactoring tutorial, I will show you how to replace a constructor with a factory method in 2 code examples.

I also received a challenge from one of you guys that I will solve. The challenge involves how to create a singleton factory method. It sounds more complicated than it is, but by watching this you’ll learn a lot. Here are some topics you may want to brush up on: Java Reflection, Factory Design Pattern, and the Singleton Design Pattern. Continue reading Code Refactoring 5

Code Refactoring 4

Code Refactoring 4I wanted to cover in this video a bunch of questions I’ve received lately. Everything after this code refactoring tutorial will be more complex.

In this video, we’ll cover converting simple types into class objects. We’ll also look at how to move fields and methods into other classes and a bunch of tricks to get the most out of that. I also show a few of the many ways Eclipse can help you write code quicker. More tips on Eclipse are planned later in the tutorial. All of the code follows the video, to help you learn.

Continue reading Code Refactoring 4

Code Refactoring 3

Code Refactoring Explaining VariablesIn this part of the code refactoring tutorial, I show you examples of how you can make your code more understandable using something called an Explaining Variable.

We also explore many short cuts people take when writing code that will cause many problems later. I want to get these basic rules out of the way so we can concentrate on refactoring to design patterns very soon in this tutorial series.

The code is available below to help you learn.

Continue reading Code Refactoring 3

Code Refactoring 2

Code Refactoring Extracting MethodsIn this part of my code refactoring tutorial I talk about some basic concepts you have to understand. I’ll cover the process of method extraction. This will help you break down many lines of code into understandable blocks. I’ll also cover when not to extract methods and how to handle temporary and local variables.

This tutorial series starts off slow, but by the end many complicated code refactorings will be covered. The code follows the video. Continue reading Code Refactoring 2

Code Refactoring

Code RefactoringWelcome to the beginning of my Code Refactoring tutorial. Code refactoring is used to improve code design to make it easier to understand and extend. Writing understandable code will allow others to easily modify it and in the end you’ll also find you write code faster because of code refactoring.

I explain what it is in the video below as well as cover the refactoring bad smells and 2 code refactorings to get you ready for what is coming. The code used follows the video. Continue reading Code Refactoring

Object Oriented Design Tutorial

Object Oriented Design TutorialHere is my whole Object Oriented Design Tutorial! The goal of this tutorial is to teach you to make beautiful Object Oriented Designs.

I start by creating a Use Case, Object Model, Sequence Diagram and Class Diagram all in the first video. I then turn those diagrams into code and a working program in the second video. I focus on teaching the Object Oriented Design process in numerous ways in this video series.

Links to all of the diagrams and code follow the 11 videos in this series.

Continue reading Object Oriented Design Tutorial