\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{DesertGarnet} \pdfinfo{ /Title (c-api-tech-interview.pdf) /Creator (Cheatography) /Author (DesertGarnet) /Subject (C\# API Tech Interview Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C\# API Tech Interview Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{DesertGarnet} via \textcolor{DarkBackground}{\uline{cheatography.com/130725/cs/30936/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}DesertGarnet \\ \uline{cheatography.com/desertgarnet} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 28th February, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{API Best Practices}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Use JSON for sending and receiving data} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Use noun instead of verbs in endpoints. {\bf{EX:}} \seqsplit{https://mysite.com/getPosts} should be https://mysite.com/posts} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Collections should use plural nouns. {\bf{EX:}} \seqsplit{https://mysite.com/post/123} should be \seqsplit{https://mysite.com/posts/123}} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Use status codes for error handling} \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Use nesting on endpoints to show relationships. {\bf{EX:}} \seqsplit{https://mysite.com/posts/author}} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Use filtering, sorting, and pagination so retrieve data requested. {\bf{EX:}} \seqsplit{https://mysite.com/posts?tags=javascript}} \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Use SSL for Security. {\bf{EX:}} https://mysite.com/posts runs on SSL and http://mysite.com/posts does not run on SSL} \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Be Clear with Versioning. Common versioning system in semantic versioning. {\bf{EX:}} 1.2.3 where 1 is the major version, 2 is the minor version, and 3 is the patch version. https://mysite.com/v1/} \tn % Row Count 20 (+ 4) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Provide accurate API documentation. {\bf{EX:}} Swagger, Postman} \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP Headers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{HTTP headers let the client and the server pass additional information with an HTTP request or response.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Request headers}} contain more information about the resource to be fetched, or about the client requesting the resource.} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Response headers}} hold additional information about the response, like its location or about the server providing it} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Representation headers}} contain information about the body of the resource, like its MIME type, or encoding/compression applied.} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Payload headers}} contain \seqsplit{representation-independent} information about payload data, including content length and the encoding used for transport.} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Basics}} \tn % Row 0 \SetRowColor{LightBackground} Types of Design Patterns & Creational, Structural, Behavioral \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{SOLID}} Principles} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{S}}ingle Responsibility Principle & A class changes for only one reason \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} {\bf{O}}pen/Closed Principle & A class should be open for extension, closed for editing \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{L}}iskov's Substitution Principle & Derived types should cleanly and easily replace base types \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} {\bf{I}}nterface Segregation Principle & Favor multiple single-purpose interfaces over composite \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{D}}ependency Inversion Principle & Concrete classes depend on abstractions, not vice-versa \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{What are design patterns?}} \newline Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Singleton}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Singleton}} is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code. Singleton has almost the same pros and cons a} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Advantages: Singleton pattern can implement interfaces. Can be lazy-loaded and has Static Initialization. It helps to hide dependencies. It provides a single point of access to a particular instance, so it is easy to maintain.} \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Disadvantages: Unit testing is a bit difficult as it introduces a global state into an application. Reduces the potential for parallelism within a program by locking.} \tn % Row Count 14 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.44333 cm} x{3.53367 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Creational}} \tn % Row 0 \SetRowColor{LightBackground} Abstract Factory & Provide an interface for creating families of related or dependent objects without specifying their concrete classes. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} Builder & Separate the construction of a complex object from its representation so that the same construction processes can create different representations. \tn % Row Count 11 (+ 6) % Row 2 \SetRowColor{LightBackground} Factory Method & Define an interface for creating an object, but let the subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. \tn % Row Count 17 (+ 6) % Row 3 \SetRowColor{white} Prototype & Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. \tn % Row Count 22 (+ 5) % Row 4 \SetRowColor{LightBackground} Singleton & Ensure a class only has one instance, and provide a global point of access to it. \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Structural}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Adapter} & Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatibility interfaces. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} Bridge & Decouple an abstraction from its implementation so that the two can vary independently. \tn % Row Count 9 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{Composite} & Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. \tn % Row Count 14 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Decorator} & Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. \tn % Row Count 19 (+ 5) % Row 4 \SetRowColor{LightBackground} Facade & Provide a unified interface to a set of interfaces in a system. Façade defines a higher-level interface that makes the subsystem easier to use. \tn % Row Count 24 (+ 5) % Row 5 \SetRowColor{white} \seqsplit{Flyweight} & Use sharing to support large numbers of fine-grained objects efficiently. A flyweight is a shared object that can be used in multiple contexts simultaneously. The flyweight acts as an independent object in each context; it's indistinguishable from an instance of the object that's not shared. \tn % Row Count 34 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Structural (cont)}} \tn % Row 6 \SetRowColor{LightBackground} Proxy & Provide a surrogate or placeholder for another object to control access to it. \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Factory Method}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The {\bf{Factory Method}} is one of the most known Design Patterns and often used when creating things with same behavior, but with different specifications.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{EX: Things with same behaviour, but different specifications: Animal Factory, Logistics Factory (delivery method or transport vehicle)} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Classes to be created cannot be determined in advance, therefore an abstract interface is provided which can be reached via a function} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A class expects from its subclasses a specification of the products to be created} \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Specialization options for subclasses, as this pattern provides an extended version of the object compared to the direct creation of the object} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Behavioral}} \tn % Row 0 \SetRowColor{LightBackground} Chain of Resp. & Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} Command & Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. \tn % Row Count 14 (+ 6) % Row 2 \SetRowColor{LightBackground} \seqsplit{Interpreter} & Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. \tn % Row Count 20 (+ 6) % Row 3 \SetRowColor{white} Iterator & Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. \tn % Row Count 25 (+ 5) % Row 4 \SetRowColor{LightBackground} Mediator & Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently. \tn % Row Count 33 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns - Behavioral (cont)}} \tn % Row 5 \SetRowColor{LightBackground} Memento & Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later. \tn % Row Count 5 (+ 5) % Row 6 \SetRowColor{white} Observer & Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. \tn % Row Count 10 (+ 5) % Row 7 \SetRowColor{LightBackground} State & Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. \tn % Row Count 14 (+ 4) % Row 8 \SetRowColor{white} Strategy & Defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients who use it. \tn % Row Count 20 (+ 6) % Row 9 \SetRowColor{LightBackground} Template Method & Define a skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithms structure. \tn % Row Count 27 (+ 7) % Row 10 \SetRowColor{white} Visitor & Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. \tn % Row Count 34 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dependency Injection Pattern}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Dependency Injection (DI) is a design pattern used to implement {\bf{IoC}}. It allows the creation of dependent objects outside of a class and provides those objects to a class through different ways. Using DI, we move the creation and binding of the dependent objects outside of the class that depends on them.} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The Dependency Injection pattern involves 3 types of classes: \{\{nl\}\} {\bf{Client Class:}} The client class (dependent class) is a class which depends on the service class. \{\{nl\}\} {\bf{Service Class:}} The service class (dependency) is a class that provides service to the client class. \{\{nl\}\} {\bf{Injector Class:}} The injector class injects the service class object into the client class.} \tn % Row Count 15 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Repository Design Pattern}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The Repository Design Pattern in C\# Mediates between the domain and the data mapping layers using a collection-like interface for accessing the domain objects. This isolates the data access code from the rest of the application.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Advantages: Changes can be done in one place. Testing the controller is easier as you don't have to test against the database.} \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}