Abstract Class VS Interface in C#

You can open any C# tutorial and you’ll find some information about abstract classes and interfaces. Most likely, you’ll not find any information about what is the difference between abstract class and interface.
This theme was discussed earlier on the Internet several times but I want to consolidate all the most important thoughts regarding the problem of choosing between an abstract class and interface in this post.
Continue reading

Designing and Implementing API in C#

Nowadays I’m writing my new programming video course. I chose an interesting topic for the next course: “Designing and Implementing API in C#”.

How to design API? In this course, you’ll learn how to design and implement types in C# so that the other developers won’t hate you when using one of the types developed by you. It means you are going to learn how to write code of the high quality: readable, understandable and reliable.

Improve your knowledge in object-oriented programming in the context of clean coding and building types of high quality.

  • Understand the characteristics of a well designed type
  • Grasp the principles of the convenient API development
  • Write clean code, get rid of unpleasant smells
  • Learn about what exceptions are intended for and how to throw and catch them properly
  • Protect your types from the incorrect usage making them properly encapsulated

And this is far from the full list of topics we will cover in this course.
Continue reading

MVVM: When EventAggregator (aka MessageBus) is an Anti-Pattern

Very often we can see that developers tend to use static message buses for all kind of interactions between objects. For those, who unaware of this pattern I want to recall that this pattern allows organizing loosely coupled communication channel between objects which don’t want (or can’t) to know each other.
Let’s have a brief look at how a regular example of using this pattern may look like:

public class Sender {
    private readonly IEventAggregator eventAggregator;

    public Sender(IEventAggregator eventAggregator) {
        this.eventAggregator = eventAggregator;
    }

    public void Action() {
        eventAggregator.Publish(new Message());
    }
}

public class Receiver : IHandle<Message> {
    public Receiver(IEventAggregator eventAggregator) {
        eventAggregator.Subscribe(this);
    }
    public void Handle(Message message) {            
    }
}

Continue reading

C# Static Code Analysis with NDepend

NDepend Icon
Have you heard about the “goto fail” fail? This is a security bug which was introduced by Apple in one of the iOS updates. Long story short, there was a piece of unreachable code which had to perform an important security check of a certificate. But it was unreachable. This is a huge defect in the software of this kind. Any meaningful static analysis tool would find that defect and any meaningful developer would fix such a bug after that. What am I talking about is that the cost of lately caught bugs is much greater than the cost of a bug caught at compile time. I don’t know how the hell Apple slipped up like that, but we are not going to discuss that. We are going to talk about static analysis.

Continue reading

Learn Enterprise WPF with XAML from Scratch

My first course “Learn Enterprise WPF with XAML from Scratch” went live on Udemy.com and it you can buy it just for 10$! It is a great WPF tutorial for beginners!

In this course, you can learn deeply the concepts and tools that you will need to build fully functional UI-applications with the modern UI-building framework, Windows Presentation Foundation (WPF).

Teaching Approach

No fluff, no ranting, no beating the air. I esteem your time. The course material is succinct, yet comprehensive. All important concepts are covered. Particularly important topics are covered in-depth. For absolute beginners, I offer my help on Skype absolutely free, if requested.

Take this course and you will be satisfied.

Build a strong foundation in WPF with this course

Today, almost all applications have rich UI, console applications are very specific. Learning the essentials of WPF puts a powerful and very useful tool at your fingertips. Being familiar with WPF will make it absolutely easy to move to Universal Windows Platform (UWP) if needed because these technologies rely basically on the same principles and they are both XAML-based.

Continue reading

Objects Equality in C#. Important Facts That You Should Know

Don’t forget that if you want to get my upcoming video courses with 50% discount, then fill the following  form.

C# provides many ways to compare objects, not only to compare class instances, but also structures. Actually, there are so many ways, that it requires to put them in order. All those possible options of comparing confuse people in case of misunderstanding them and their possible implementations.

Continue reading

Cryptography in .NET for Beginners

This is a brief introduction into .NET cryptography.

Hashes

Hashing is a transformation process of some input data of an arbitrary length into an array of bytes of fixed size.
Hash is a one-side transformation function, the result of which cannot be reversed for receiving original input data. Very often it is used to store passwords. Even if an attacker gets a hash, he can’t retrieve the password from it. The length of a hash is determined by a hashing algorithm. In .NET you can find the following hashing algorithms (all of which derive from the HashAlgorithm base class):

  • MD5 — 128 bits in length
  • SHA (Secure Hash Algorithm) — there is no such a class, but there are SHA1 (160 bits), SHA256, SHA384, SHA512
  • KeydHashAlgorithm (also known as Message Authentication Code). Represented by the following classes of  algorithms: HMAC and MACTripleDES

Continue reading

Money Type as Value Object, or Don’t Rely on Primitive Types!

Primitive Types Obsession Problem

Today I’m going to discuss the problem of using primitive types instead of abstractions. This problem was discussed in the blog of Mark Seemann. Read it, if you haven’t read it yet.
In this post I’m going to talk about Money type as an abstraction instead of using decimal type for representing money-values.
In the last project I’ve been participating in, we relied on a decimal and integer types for a long time. From the beginning, we knew that using primitive types for values of that kind is an anti-pattern, but we stubbornly have been using them. In the US there are cents and dollars. In the Russian Federation – rubles and kopeks. 1 ruble = 100 kopeks. Our system inter-operated with an external system which performed all its calculations in kopeks. So it required kopeks as the input and returned kopeks as the output. If we wanted to pass in 2rubles and 50kopeks, then we passed in Int32 amount = 250;

Continue reading