#PARAN SILVERLIGHT#
  • Tistory
    • 관리자
    • 글쓰기
Carousel 01
Carousel 02
Previous Next

자동 속성을 이용한 데이타 캡슐화

PROGRAMING/C# 2012. 11. 21. 15:17

Singleton DB Connection 예제를 가지고 자동 속성을 사용하여 데이타 캡슐화를 해보자.


    public class SingletonConnection

    {

        private volatile static SingletonConnection uniqueInstance;

        private static object syncRoot = new Object();

        

  //캡슐화 할 멤버 변수를 선언

  private static string strConnectionString;

        private SqlConnection sqlConnection;

        #endregion


  //속성을 구현

        public static string ConnectionString

        {

            get { return strConnectionString; }

            set { strConnectionString = value; }

        }

        public SqlConnection SqlConnection

        {

            get { return sqlConnection; }

        }


        private SingletonConnection()

        {

      //Class 안에서만 Set을 할 수 있다

            sqlConnection = new SqlConnection(strConnectionString);

        }



        public static SingletonConnection GetInstance()

        {

            if (uniqueInstance == null)

            {

                lock (syncRoot)

                {

                    if (uniqueInstance == null)

                    {

                        uniqueInstance = new SingletonConnection();

                    }

                }

            }

            return uniqueInstance;

        }

        #endregion

    }




    public class SinglitonDBConnection

    {


        private volatile static SinglitonDBConnection uniqueInstance;

        private static object syncRoot = new Object();


        //자동 속성을 사용해서 변경

        public static string StrConnectionString { get; set; }

         //Class 안에서만 변경할 수 있도록 private로 추가

        public SqlConnection SqlConnection { get; private set; }


        private SinglitonDBConnection()

        {

            SqlConnection = new OleDbConnection(StrConnectionString);

        }


        public static SinglitonDBConnection GetInstance()

        {

            if (uniqueInstance == null)

            {

                lock (syncRoot)

                {

                    if (uniqueInstance == null)

                    {

                        uniqueInstance = new SinglitonDBConnection();

                    }

                }

            }

            return uniqueInstance;

        }


    }






저작자표시 비영리 (새창열림)
블로그 이미지

파란실버라이트

To remember the time when I started learning Silver Light!

,

카테고리

  • Inforamtion Technology (281)
    • DESIGN PATTERN (33)
      • 실용주의 디자인패턴 (29)
    • SOFTWARE ENGINEERING (21)
      • Art Of Readable Code (12)
      • Object Oriented Programming (6)
      • TDD (2)
    • FRAMEWORK (22)
      • Spring.net (2)
      • LightSwitch (20)
    • PROGRAMING (58)
      • C# (20)
      • .NET (6)
      • HTML5 (7)
      • ASP.NET (9)
      • SILVERLIGHT (7)
      • Ruby On Rails (6)
    • PROJECT MANAGEMENT (10)
      • SW Version Management (7)
      • Schedulring Management (1)
    • BOOKS (18)
    • MOBILE APP (1)
      • SENCHA TOUCH (1)
    • SECURITY (5)
    • MES (1)
    • B2B (14)
      • WEBMETHODS (4)
    • ERP (53)
      • SAP/R/3 (51)
    • ABOUT TOOLS (2)
    • FUNDAMENT CONCEPT (21)
    • SOA BPM (22)
    • PORTFOLIO (0)

태그목록

  • 병렬
  • 프로그래밍
  • 동시성

최근에 받은 트랙백

글 보관함

링크

파란실버라이트

블로그 이미지

To remember the time when I started learning Silver Light!

LATEST FROM OUR BLOG

RSS 구독하기

LATEST COMMENTS

BLOG VISITORS

  • Total :
  • Today :
  • Yesterday :

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바