Some Design Pattern in .NET C#

Preview:

DESCRIPTION

It's about Singleton Pattern, Factory Methods and something called Privacy Leaks.

Citation preview

Gilang Abdul Aziz

Singleton Pattern

Singleton Pattern

Class hanya bisa diinstansiasi paling banyak 1 kali.

Singleton Pattern

How?

Singleton Pattern

Private Constructor

Singleton Pattern

static method,Instance()

Singleton Pattern

static method,Instance()

Private Constructor

Singleton Pattern

static method,Instance()

Private Constructor

uniqueInstance NULL?new Singleton()

Singleton Pattern

Example :

Singleton Pattern

Example of use:

Singleton Pattern

Example of use:

Factory Methods

Factory Methods

Direct use of constructors is not flexible enough

In some situations

Factory Methods

For example: Class Point (in earlier chapter)Wee need constructor for both Polar or Rectangular initialization

And it’s need 2 parameters.

Factory Methods

And it’s SUX!

How?

Factory Methods

Private Constructor

Factory Methods

Create Methods Who

Delegate their work to the private constructor

Factory Methods

Factory Methods

Example :Factory Methods

Example :Factory Methods

Privacy Leaks

Privacy Leaks

A method can return part of its private state, which can be mutated outside the object

Privacy Leaks

And it’s COMPLICATED!

Let’s see how it works :Privacy Leaks

Let’s see how it works :

Privacy Leaks

Let’s see how it works :

Privacy Leaks

HORRAAY !!!

Gilang Abdul Aziz@Ltheordinary

Recommended