WORKSHOP 17. - 18. april 2012
New language features in Delphi
“Nick Hodges is the Product Development Manager for Gateway Ticketing Systems in Boyertown, PA. A former Delphi R&D Manager and Product Manager, Nick has been using Delphi since the very beginning. He's spoken at numerous conferences and user groups all over the world and is a former member of the Borcon Advisory Board. He's written countless articles, blog posts, and book chapters on a wide range of Delphi topics. Nick lives in Gilbertsville, PA with his wife and three children.”
This two day workshop will cover
the newest language features in Delphi and some of the frameworks and
techniques enabled by them. The emphasis will be placed on modern
coding patterns and techniques that enable you to write better, cleaner
code and to avoid entire classes of bugs with features like dependency
injection, unit testing, and mocking.
Day One: Language Features Introductions
In this module, we’ll look at the most recent advances in the Delphi language and how they can be used to make your code cleaner and more powerful.
Interfaces are a powerful way to abstract and decouple your code. Knowing how they work and what they can do for you will go a long way towards improving your code. In this section, we’ll learn how to declare, implement, and use interfaces.
Generics provide the ability to write code that provides the same functionality for many different types. In this section we’ll learn how to declare, implement, and use generic types.
Anonymous Methods allow you to declare “chunks” of code that can be passed as variables and called when desired. In this section we’ll see how you can define an anonymous method type, and then use it to pass different code chunks to perform different tasks as desired.
Using the New Language Features
Collections are any class that can contain other classes or types. Combined with generics, collections can become very powerful ways to manage data and information.
IEnumerable is a very special interface that allows you to iterate over collections and other lists, choosing specific items based on specific criteria. In this section, we’ll use the IEnumerable implementation in the Delphi Spring Framework to illustrate the power of this interesting code construct.
Predicates are a very special type of anonymous method that enable you to easily filter through data. In this section, we’ll use predicates to show how you can pick and choose amongst items within an enumeration.
Day Two: Language Feature Applications
Dependency Injection is a powerful coding pattern that helps to decouple and simplify your code. When used properly and effectively, it can improve the testability and increase the maintainability of your code.
In this first section, we’ll look at the basics of Dependency Injection and the simple steps you can take to start making dependency injection the normal pattern in your code.
Using a DI Container
Having covered the basics, we’ll examine the use of the Dependency Injection container that comes as part of the Delphi Spring Framework.
With few exceptions, developers should unit test all the code that they write. This module will cover the why’s and how’s of unit testing
What is Unit Testing?
Unit testing is critical to producing good, clean code. In this section we’ll discuss the benefits of unit testing, and then go through an exercise that illustrates good unit testing practices.
DUnit is a framework for doing unit testing in Delphi. In this section we’ll explore how you can use DUnit to write good unit tests.
A critical part of unit testing is testing your code in isolation. Mocking is a technique you can use – in tandem with good dependency injection techniques – to “fake” the dependencies your classes have to enable testing in isolation.
This section will introduce the Delphi Mocks framework, and how it can be used to create fake but useful dependencies for injection into your classes under test
This section will cover the advanced features of the Delphi Mocks framework, including the ability to define specific expectations, catching expected exceptions, and other advanced techniques.