{TIL} Class 특강

Kwaksang·2024년 4월 30일

TIL

목록 보기
10/37
post-thumbnail

Class 특강

Chapter .1 Class 특강

Content .1 Class의 구성 요소

  1. 데이터 (변수)
  2. 기능 / 논리 (함수 or Methods or Functions)
  3. 생성자 / 소멸자

Content .2 데이터의 구성 요소

  1. 단일데이터
  2. 배열 / 리스트
  3. 구조체 / 클래스 (단, 이중클래스 지양)

Content .3 철학적 개념

  1. 플라톤 : Class (이데아) -> 우리가 사용하는 방식
  2. 아리스토텔레스 : Prototype

Apple apple = new Apple();

// 이데아 세계(Class)에서 현재 세계(작업 공간)로 가져오는 작업
// 객체화, Instance화

Content .4 메모리 영역의 이해

  1. 코드 영역 : 실행할 프로그램의 코드
  2. 데이터 영역 : 전역 변수, 정적 변수 (static 사용)
  3. 힙 영역 : 사용자의 동적 할당
  4. 스택 영역 : 지역 변수, 매개 변수

Content .5 힙(Heap)과 스택(Stack) 영역

  1. 값형식 : 선언 & 값 모두 스택 메모리만 사용
  2. 참조형식 : 선언은 스택 메모리 & 값은 힙 메모리를 사용
  • 스택 메모리에서 힙 메모리의 주소 값을 사용

Apple apple1 = new Apple();
Apple apple2 = apple1;

// 위와 같은 경우는 apple1과 apple2가 같은 주소값을 가지게 됨

Content .6 초기데이터 세팅값 활용하기

  • ex) Apple apple = new Apple(초기데이터 세팅값);
// 예시 사과

class Apple
{
    public int sweet = 5;
    public float hardless = 2.0f;
    public Color color = Color.Green;
    public string name = "Aori";
    public string productLocation = "An-dong";

// 위 데이터 더미들은 힙 메모리에 저장됨

    public Apple(int _sweet, float _hardless, Color _color, string _name, string _productLocation)
    {
        sweet = _sweet;
        hardless = _hardless;
        color = _color;
        name = _name;
        productLocation = _productLocation;
    }

    public Apple(string _productLocation)
    {
        productLocation = _productLocation;
    }

    public Apple()
    {

    }
}

class FileName
{
    static void Main()
    {
        Apple hongro = new Apple(6, 4.0f, Color.Red, "hongro", "Chengsong");
        Apple aori = new Apple();
        Apple choongju = new Apple("choongju");
    }
}

Content .7 클래스 치환하기

// 예시 자전거 클래스 치환

class Bike
{
    public string frame;
    public int price;
    public string factory;
    public string company;

    public Wheel frontwheel;
    public Wheel rearwheel;
}

class Wheel()
{
    public int size;
    public Color color;
    public Tire tire;
    public string company;
}

아직은 다소 생소하고 어려운 부분이기에 지속적인 복습과 연습이 필요한 파트
항상 봐오던 정답 풀이 해설에서 이해가 안가던 부분이 약간은 이해가 되기 시작

profile
게임은 재미와 기능!

0개의 댓글