Show Menu

FunctionalDesign Cheat Sheet (DRAFT) by [deleted]

Summary of:

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.


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

SOLID (ext)

a class should have only a single respon­sib­ility
“software entities … should be open for extension, but closed for modifi­cat­ion.”
“objects in a program should be replac­eable with instances of their subtypes without altering the correc­tness of that program.”
“many client­-sp­ecific interfaces are better than one genera­l-p­urpose interf­ace.”
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(
            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);