Top Banner
Gilang Abdul Aziz
30

Some Design Pattern in .NET C#

May 24, 2015

Download

Technology

Gilang Aziz

It's about Singleton Pattern, Factory Methods and something called Privacy Leaks.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Some Design Pattern in .NET C#

Gilang Abdul Aziz

Page 2: Some Design Pattern in .NET C#

Singleton Pattern

Page 3: Some Design Pattern in .NET C#

Singleton Pattern

Class hanya bisa diinstansiasi paling banyak 1 kali.

Page 4: Some Design Pattern in .NET C#

Singleton Pattern

How?

Page 5: Some Design Pattern in .NET C#

Singleton Pattern

Private Constructor

Page 6: Some Design Pattern in .NET C#

Singleton Pattern

static method,Instance()

Page 7: Some Design Pattern in .NET C#

Singleton Pattern

static method,Instance()

Private Constructor

Page 8: Some Design Pattern in .NET C#

Singleton Pattern

static method,Instance()

Private Constructor

uniqueInstance NULL?new Singleton()

Page 9: Some Design Pattern in .NET C#

Singleton Pattern

Example :

Page 10: Some Design Pattern in .NET C#

Singleton Pattern

Example of use:

Page 11: Some Design Pattern in .NET C#

Singleton Pattern

Example of use:

Page 12: Some Design Pattern in .NET C#
Page 13: Some Design Pattern in .NET C#

Factory Methods

Page 14: Some Design Pattern in .NET C#

Factory Methods

Direct use of constructors is not flexible enough

In some situations

Page 15: Some Design Pattern in .NET C#

Factory Methods

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

And it’s need 2 parameters.

Page 16: Some Design Pattern in .NET C#

Factory Methods

And it’s SUX!

Page 17: Some Design Pattern in .NET C#

How?

Factory Methods

Page 18: Some Design Pattern in .NET C#

Private Constructor

Factory Methods

Page 19: Some Design Pattern in .NET C#

Create Methods Who

Delegate their work to the private constructor

Factory Methods

Page 20: Some Design Pattern in .NET C#

Factory Methods

Page 21: Some Design Pattern in .NET C#

Example :Factory Methods

Page 22: Some Design Pattern in .NET C#

Example :Factory Methods

Page 23: Some Design Pattern in .NET C#
Page 24: Some Design Pattern in .NET C#

Privacy Leaks

Page 25: Some Design Pattern in .NET C#

Privacy Leaks

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

Page 26: Some Design Pattern in .NET C#

Privacy Leaks

And it’s COMPLICATED!

Page 27: Some Design Pattern in .NET C#

Let’s see how it works :Privacy Leaks

Page 28: Some Design Pattern in .NET C#

Let’s see how it works :

Privacy Leaks

Page 29: Some Design Pattern in .NET C#

Let’s see how it works :

Privacy Leaks

Page 30: Some Design Pattern in .NET C#

HORRAAY !!!

Gilang Abdul Aziz@Ltheordinary