SlideShare a Scribd company logo
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
System.Activator
public class C {
  public C() { … }
}




public class C {
  public static C NewC() {
    return new C();
  }
}
private



          base()   this()
class PersonFactory {
  public Person MakePerson(
    int age)
  {
    if (age < 18)
      return new Minor();
    else
      return new Adult();
  }
}
string.Format(
  “<person name=”{0}”,
  name)




XElement(“person”,
  XAttribute(“name”, name))
  .ToString();
Design Patterns in .Net
StringBuilder        AppendFormat()
AppendLine()

  Util.AppendFormatLine(stringBuilder, format, params)

  stringBuilder.AppendFormatLine(format, params)


stringBuilder.AppendFormat(“… {0}”, params,
Environment.NewLine)
Design Patterns in .Net
MemberwizeClone


ICloneable
              Clone()




ToString() GetHashCode()
[Serializable]
public abstract class IPrototype<T>
{
  public T DeepCopy()
  {
    MemoryStream stream = new MemoryStream();
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(stream, this);
    stream.Seek(0, SeekOrigin.Begin);
    T copy = (T)formatter.Deserialize(stream);
    stream.Close();
    return copy;
  }
}
DeepCopy
                 IPrototype<T>



 
 
 WeakReference
new
public class C
{
  private C() { /* nothing here */ }

    class CMaker {
      static CMaker () { }
      internal static readonly C instance = new C();
    }

    public static C Instance {
      get { return CMaker.instance; }
    }
}
x:Static
Design Patterns in .Net
Design Patterns in .Net
Random
class RandomGenerator {
  public Random GetRandom() {
    return new Random(); // not what I want
  }
}

interface IRandom {
  int RandomNumber();
}
RandomGenerator
          IRandom


class RandomAdapter:
  RandomGenerator, IRandom
{
  int RandomNumber() {
    return GetRandom().Next();
  }
}
– RandomGenerator rg = new RandomGenerator();
  Random r = rg.GetRandom();


– IRandom rand = new Adapter();
  int n = rand.RandomNumber();
Design Patterns in .Net
– class C { … }
– class CCollection : Collection<C> { … }

 class CContainer {
   private Collection<C> items;
 }
class Neuron
{ … }

class Layer :
Collection<Neuron>
{ … }

neuron.ConnectTo(otherNeuron);
neuron.ConnectTo(layer);
layer.ConnectTo(neuron);
layer.ConnectTo(otherLayer);
– IEnumerable<T>
            yield return this;

     ICollection<T>
Design Patterns in .Net
Card   CardInPlay

♣ ♠ ♥ ♦

                    Rank
                    Suit
          Rank
          Suit
                 Orientation
Design Patterns in .Net
IA   IB
 A   B
Design Patterns in .Net
→
→
Design Patterns in .Net
new
               Bitmap
      byte[]
Reflection.Emit
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
XElement.Parse
      →
IEnumerable<T>
   yield return
GetEnumerator()

  AsyncEnumerator
Design Patterns in .Net
Design Patterns in .Net
Design Patterns in .Net
→

→
Design Patterns in .Net
interface ICarState
{
  void Go(Context ctx); // Drive?
}
class Context {
  ICarState state;
  public void GoGoGo() {
    state.Go(this);
    state.Go(this); // yeah, right :)
    state.Go(this);
  }
}
class CrashedState :            class MovingState :
ICarState                       ICarState
{                               {
  void Go(Context ctx)            void Go(Context ctx)
  {                               {
    MessageBox.Show(                // driving
      “Are you crazy?”);            // is that a rock?
  }
}                                       // CRASH!
                    The state           ctx.state =
                       just               new CrashedState();
                     changed!       }
                                }
Design Patterns in .Net
Design Patterns in .Net
interface IStrategy
{
  void Evaluate(Context ctx);
}

SingleEvaluator, ParralelEvaluator,
GpuEvaluator
class Context {
  IStrategy strategy;
  Matrix m1, m2;
  static void Multiply(Matrix m1, Matrix m2)
  { this.m1 = m1; this.m2 = m2;
    if (strategy == null) { // on-demand
      if (gpu.pixelShader >= 2.0)
        strategy = new GpuStrategy();
      else if (Environment.ProcessorCount > 1)
        strategy = new ParallelStrategy();
      else strategy = new SingleStrategy();
    }
    strategy.Evaluate(this);
  }
}
→
    →
StringBuilder
Design Patterns in .Net
Design Patterns in .Net


More Related Content

What's hot (20)

Fisica ii codigo
Fisica ii codigoFisica ii codigo
Fisica ii codigo
eaceved5
 
Node.js and angular js
Node.js and angular jsNode.js and angular js
Node.js and angular js
HyungKuIm
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
C4Media
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
Litebox
LiteboxLitebox
Litebox
meli media
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
DEVTYPE
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
Kazutaka Tomita
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
Низкоуровневые оптимизации .NET-приложений
Низкоуровневые оптимизации .NET-приложенийНизкоуровневые оптимизации .NET-приложений
Низкоуровневые оптимизации .NET-приложений
Andrey Akinshin
 
Boxing & unboxing
Boxing & unboxingBoxing & unboxing
Boxing & unboxing
Larry Nung
 
iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with Blocks
Jeff Kelley
 
Functional JavaScript for everyone
Functional JavaScript for everyoneFunctional JavaScript for everyone
Functional JavaScript for everyone
Bartek Witczak
 
LOFAR - finding transients in the radio spectrum
LOFAR - finding transients in the radio spectrumLOFAR - finding transients in the radio spectrum
LOFAR - finding transients in the radio spectrum
Gijs Molenaar
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
Alexander Mostovenko
 
The jsdom
The jsdomThe jsdom
The jsdom
Domenic Denicola
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
Anand Dhana
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
Roy Rutto
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
Teerawat Issariyakul
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
Fisica ii codigo
Fisica ii codigoFisica ii codigo
Fisica ii codigo
eaceved5
 
Node.js and angular js
Node.js and angular jsNode.js and angular js
Node.js and angular js
HyungKuIm
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
C4Media
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
DEVTYPE
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
Kazutaka Tomita
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
Низкоуровневые оптимизации .NET-приложений
Низкоуровневые оптимизации .NET-приложенийНизкоуровневые оптимизации .NET-приложений
Низкоуровневые оптимизации .NET-приложений
Andrey Akinshin
 
Boxing & unboxing
Boxing & unboxingBoxing & unboxing
Boxing & unboxing
Larry Nung
 
iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with Blocks
Jeff Kelley
 
Functional JavaScript for everyone
Functional JavaScript for everyoneFunctional JavaScript for everyone
Functional JavaScript for everyone
Bartek Witczak
 
LOFAR - finding transients in the radio spectrum
LOFAR - finding transients in the radio spectrumLOFAR - finding transients in the radio spectrum
LOFAR - finding transients in the radio spectrum
Gijs Molenaar
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
Alexander Mostovenko
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
Anand Dhana
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
Roy Rutto
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 

Viewers also liked (20)

Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
Aniruddha Chakrabarti
 
Some Design Pattern in .NET C#
Some Design Pattern in .NET C#Some Design Pattern in .NET C#
Some Design Pattern in .NET C#
Gilang Aziz
 
Interviewing Skills - Lesson 1
Interviewing Skills - Lesson 1Interviewing Skills - Lesson 1
Interviewing Skills - Lesson 1
SkimaTalk
 
Angular js
Angular jsAngular js
Angular js
ParmarAnisha
 
Angular js
Angular jsAngular js
Angular js
Manav Prasad
 
LESSON PLAN Basic sentence pattern
LESSON PLAN Basic sentence patternLESSON PLAN Basic sentence pattern
LESSON PLAN Basic sentence pattern
Pristine Estorque
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
Ganesh Samarthyam
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
Jamie (Taka) Wang
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
Ansuman Roy
 
Patterns number and geometric
Patterns  number and geometricPatterns  number and geometric
Patterns number and geometric
amdzubinski
 
Get satrted angular js
Get satrted angular jsGet satrted angular js
Get satrted angular js
Alexandre Marreiros
 
Repeating and growing patterns
Repeating and growing patternsRepeating and growing patterns
Repeating and growing patterns
Jessica Weesies
 
Angular 2
Angular 2Angular 2
Angular 2
Nigam Goyal
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
Akshay Mathur
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Object-oriented design patterns  in UML [Software Modeling] [Computer Science...Object-oriented design patterns  in UML [Software Modeling] [Computer Science...
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Ivano Malavolta
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Some Design Pattern in .NET C#
Some Design Pattern in .NET C#Some Design Pattern in .NET C#
Some Design Pattern in .NET C#
Gilang Aziz
 
Interviewing Skills - Lesson 1
Interviewing Skills - Lesson 1Interviewing Skills - Lesson 1
Interviewing Skills - Lesson 1
SkimaTalk
 
LESSON PLAN Basic sentence pattern
LESSON PLAN Basic sentence patternLESSON PLAN Basic sentence pattern
LESSON PLAN Basic sentence pattern
Pristine Estorque
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
Ganesh Samarthyam
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Patterns number and geometric
Patterns  number and geometricPatterns  number and geometric
Patterns number and geometric
amdzubinski
 
Repeating and growing patterns
Repeating and growing patternsRepeating and growing patterns
Repeating and growing patterns
Jessica Weesies
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
Akshay Mathur
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Object-oriented design patterns  in UML [Software Modeling] [Computer Science...Object-oriented design patterns  in UML [Software Modeling] [Computer Science...
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Ivano Malavolta
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Ad

Similar to Design Patterns in .Net (20)

Spring data access
Spring data accessSpring data access
Spring data access
명철 강
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML Schema
Raji Ghawi
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
John Ferguson Smart Limited
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
Jieyi Wu
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
kenbot
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
Chandra Sekhar Nayak
 
Map kit light
Map kit lightMap kit light
Map kit light
CocoaHeads France
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
arjuncorner565
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
shaktisinhgandhinaga
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
RithikRaj25
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
Juan Pablo
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
Karuppaiyaa123
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Ss
SsSs
Ss
Karan Soni
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камни
Stfalcon Meetups
 
Spring data access
Spring data accessSpring data access
Spring data access
명철 강
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML Schema
Raji Ghawi
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
Jieyi Wu
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
kenbot
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
arjuncorner565
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
shaktisinhgandhinaga
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
Juan Pablo
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
Karuppaiyaa123
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камни
Stfalcon Meetups
 
Ad

More from Dmitri Nesteruk (20)

Good Ideas in Programming Languages
Good Ideas in Programming LanguagesGood Ideas in Programming Languages
Good Ideas in Programming Languages
Dmitri Nesteruk
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern Observations
Dmitri Nesteruk
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
Dmitri Nesteruk
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
Dmitri Nesteruk
 
C# Tricks
C# TricksC# Tricks
C# Tricks
Dmitri Nesteruk
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming Bots
Dmitri Nesteruk
 
Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++
Dmitri Nesteruk
 
Monte Carlo C++
Monte Carlo C++Monte Carlo C++
Monte Carlo C++
Dmitri Nesteruk
 
Tpl DataFlow
Tpl DataFlowTpl DataFlow
Tpl DataFlow
Dmitri Nesteruk
 
YouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerYouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue Tracker
Dmitri Nesteruk
 
Domain Transformations
Domain TransformationsDomain Transformations
Domain Transformations
Dmitri Nesteruk
 
Victor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIVictor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UI
Dmitri Nesteruk
 
Developer Efficiency
Developer EfficiencyDeveloper Efficiency
Developer Efficiency
Dmitri Nesteruk
 
Distributed Development
Distributed DevelopmentDistributed Development
Distributed Development
Dmitri Nesteruk
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data Integration
Dmitri Nesteruk
 
Web mining
Web miningWeb mining
Web mining
Dmitri Nesteruk
 
Data mapping tutorial
Data mapping tutorialData mapping tutorial
Data mapping tutorial
Dmitri Nesteruk
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
Dmitri Nesteruk
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
Dmitri Nesteruk
 
Good Ideas in Programming Languages
Good Ideas in Programming LanguagesGood Ideas in Programming Languages
Good Ideas in Programming Languages
Dmitri Nesteruk
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern Observations
Dmitri Nesteruk
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
Dmitri Nesteruk
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
Dmitri Nesteruk
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming Bots
Dmitri Nesteruk
 
Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++
Dmitri Nesteruk
 
YouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerYouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue Tracker
Dmitri Nesteruk
 
Victor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIVictor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UI
Dmitri Nesteruk
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data Integration
Dmitri Nesteruk
 

Recently uploaded (20)

Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Compliance-as-a-Service document pdf text
Compliance-as-a-Service document pdf textCompliance-as-a-Service document pdf text
Compliance-as-a-Service document pdf text
Earthling security
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Compliance-as-a-Service document pdf text
Compliance-as-a-Service document pdf textCompliance-as-a-Service document pdf text
Compliance-as-a-Service document pdf text
Earthling security
 

Design Patterns in .Net

  • 9. public class C { public C() { … } } public class C { public static C NewC() { return new C(); } }
  • 10. private base() this()
  • 11. class PersonFactory { public Person MakePerson( int age) { if (age < 18) return new Minor(); else return new Adult(); } }
  • 12. string.Format( “<person name=”{0}”, name) XElement(“person”, XAttribute(“name”, name)) .ToString();
  • 14. StringBuilder AppendFormat() AppendLine() Util.AppendFormatLine(stringBuilder, format, params) stringBuilder.AppendFormatLine(format, params) stringBuilder.AppendFormat(“… {0}”, params, Environment.NewLine)
  • 16. MemberwizeClone ICloneable Clone() ToString() GetHashCode()
  • 17. [Serializable] public abstract class IPrototype<T> { public T DeepCopy() { MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, this); stream.Seek(0, SeekOrigin.Begin); T copy = (T)formatter.Deserialize(stream); stream.Close(); return copy; } }
  • 18. DeepCopy IPrototype<T>   WeakReference
  • 19. new
  • 20. public class C { private C() { /* nothing here */ } class CMaker { static CMaker () { } internal static readonly C instance = new C(); } public static C Instance { get { return CMaker.instance; } } }
  • 24. Random class RandomGenerator { public Random GetRandom() { return new Random(); // not what I want } } interface IRandom { int RandomNumber(); }
  • 25. RandomGenerator IRandom class RandomAdapter: RandomGenerator, IRandom { int RandomNumber() { return GetRandom().Next(); } }
  • 26. – RandomGenerator rg = new RandomGenerator(); Random r = rg.GetRandom(); – IRandom rand = new Adapter(); int n = rand.RandomNumber();
  • 28. – class C { … } – class CCollection : Collection<C> { … } class CContainer { private Collection<C> items; }
  • 29. class Neuron { … } class Layer : Collection<Neuron> { … } neuron.ConnectTo(otherNeuron); neuron.ConnectTo(layer); layer.ConnectTo(neuron); layer.ConnectTo(otherLayer);
  • 30. – IEnumerable<T> yield return this; ICollection<T>
  • 32. Card CardInPlay ♣ ♠ ♥ ♦ Rank Suit Rank Suit Orientation
  • 34. IA IB A B
  • 38. new Bitmap byte[]
  • 45. IEnumerable<T> yield return GetEnumerator() AsyncEnumerator
  • 51. interface ICarState { void Go(Context ctx); // Drive? }
  • 52. class Context { ICarState state; public void GoGoGo() { state.Go(this); state.Go(this); // yeah, right :) state.Go(this); } }
  • 53. class CrashedState : class MovingState : ICarState ICarState { { void Go(Context ctx) void Go(Context ctx) { { MessageBox.Show( // driving “Are you crazy?”); // is that a rock? } } // CRASH! The state ctx.state = just new CrashedState(); changed! } }
  • 56. interface IStrategy { void Evaluate(Context ctx); } SingleEvaluator, ParralelEvaluator, GpuEvaluator
  • 57. class Context { IStrategy strategy; Matrix m1, m2; static void Multiply(Matrix m1, Matrix m2) { this.m1 = m1; this.m2 = m2; if (strategy == null) { // on-demand if (gpu.pixelShader >= 2.0) strategy = new GpuStrategy(); else if (Environment.ProcessorCount > 1) strategy = new ParallelStrategy(); else strategy = new SingleStrategy(); } strategy.Evaluate(this); } }
  • 58.
  • 62.