Show Menu
Cheatography

FunctionalDesign Cheat Sheet (DRAFT) by [deleted]

Summary of: http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-functional/

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Main Ideas

Objects and closures seem closely related
Closure is an important concept in Functional Progra­mming
SOLID principles lead to a style of design that makes Functional Progra­mming quite attrac­tive.
 

SOLID

Single Respon­sib­ility (SRP)
Open/c­losed (OCP)
Liskov substi­tution (LSP)
Interface segreg­ation (ISP)
Dependency inversion (DIP)

SOLID (ext)

SRP
a class should have only a single respon­sib­ility
OCP
“software entities … should be open for extension, but closed for modifi­cat­ion.”
LSP
“objects in a program should be replac­eable with instances of their subtypes without altering the correc­tness of that program.”
ISP
“many client­-sp­ecific interfaces are better than one genera­l-p­urpose interf­ace.”
DIP
one should “depend upon abstra­ctions, [not] concre­tio­ns.”[
 

Object (Data with behaviour)

public class FileStore : IMessageQuery
{
    private readonly DirectoryInfo workingDirectory;

    public FileStore(DirectoryInfo workingDirectory)
    {
        this.workingDirectory = workingDirectory;
    }

    public string Read(int id)
    {
        var path = Path.Combine(
            this.workingDirectory.FullName,
            id + ".txt");            
        return File.ReadAllText(path);
    }
}

Closure (Behaviour with data)

var workingDirectory = new DirectoryInfo(Environment.CurrentDirectory);
Func<int, string> read = id =>
    {
        var path = Path.Combine(workingDirectory.FullName, id + ".txt");
        return File.ReadAllText(path);
    };