O'Reilly logo
live online training icon Live Online training

Object Oriented Programming in C# and .NET Core

Object Creation: from Classical Design Patterns to Dependency Injection

Riccardo Audano

Object oriented programming is not only about learning the syntax of class, interface, and object creation; it‘s also about object oriented design, and mastering the “how” and “why” of using classes, interfaces, and objects.

Just as you have to organize your code inside your classes and functions you need to able to structure the design of your software and how the classes you write will interact with each other. Polymorphism ‘sounds’ difficult, but it’s actually an easy concept to understand. What is a bit less easy to understand is why and how polymorphism is so central to object oriented programming. This is the next step that we must take after learning the fundamentals of the language, and design patterns are the basic vocabulary to become proficient at object oriented design. In this course, we will look at how creational design patterns and a dependency injection can help make our code more flexible, testable, and extensible.

What you'll learn-and how you can apply it

By the end of this live online course you’ll understand:

  • The limitations of direct use of contractors
  • The advantages of “programming to an interface”
  • What Design Patterns are and why they are useful
  • The classic GOF creational patterns
  • The vocabulary and principles of Object Oriented Design
  • Why a dependency injection framework is useful, and how the dependency injection facilities of ASP.NET MVC Core can make our code more flexible, with an example of the “Unit of Work - Repository” architectural pattern.

And you will be able to:

  • Understand design choices in the libraries and framework that you use
  • Save time and avoid mistakes by applying a variety of proven solutions to your design problems
  • Create software with a clean design that’s easy to understand and maintain.
  • Transition from “coder” to “software engineer”

This training course is for you because...

This session is targeted to programmers who want to go beyond the syntax and “algorithm implementation” features of the C# language and learn what Object Oriented Programming is all about -- creating software with a clean design that is easy to extend.

Prerequisites

Working knowledge of the C# language and a basic understanding of class inheritance, interface implementation and method overrides.

About your instructor

  • Riccardo Audano is a developer and tech trainer with more than 15 years of professional experience. He suspects that his not so linear course of studies and interests development has helped him to integrate some of the strengths of the humanities, pure science and coding, starting with the classical studies of his high school, then getting his bachelor and MS in Astronomy, and finally making the choice (with sometimes he regrets, sometimes not) to leave the academia and go work "in the real world". Coming from a background in C/C++ he naturally evolved to Java and C# while getting more and more interested in object oriented principles, design and architecture. He loves programming, but has gradually found out that there's something he likes even more, and that is teaching programming, getting more people into the field and helping existing developers to progress in their understanding and career. Along the years he's taught classes in UML. C/C++/C#. Java, JavaScript, PHP, T-SQL, PL/SQL and Python. He prefers a very interactive teaching style, based on "learning sessions" and not "lessons" and always strives to make them lively, informal and fun. To this extent, he thinks that for a fun introduction to programming nothing beats game programming, so he often uses Unity3D, LibGDX and Phaser in his intro classes.

    When he's not obsessing with coding he's probably travelling, or trying to improve his French and Portuguese and dreaming about learning Chinese, or playing any sport that's played with a racket, be it tennis, beach tennis or paddle, and this is the only activity where you will find him yelling and cursing even louder than when a line of code does not behave as he thinks it should.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Section 1: Introduction to Object Oriented Design and Design Patterns. Fundamental ideas (approx 10 mins)

  • Birth of the Design Patterns idea
  • Inheritance vs. Composition
  • The importance of programming to an interface

Section 2: Object Creation and why it is a problem: Factory Patterns (approx 60 mins)

  • Limits imposed by direct use of constructors
  • A simple hack: the factory method idiom
  • Classical GOF solutions: Builder and Factory Method.

Break

  • The most complex and powerful GOF creational pattern: Abstract Factory
  • Exercise: Abstract Factory Implementation. (approx 15 mins)

Section 3: Object Creation on steroids: using Dependency Injection (approx 40 mins)

  • Dependency Inversion Principle and Dependency Injection
  • Repository Pattern with Entity Framework Core
  • Example of dependency injection in MVC Core: implementation of the Unit of Work
  • Exercise: using Dependency Injection with testing (approx 15 mins)

Recap and final discussion (approx 10 mins)