250x250
Notice
Recent Posts
Recent Comments
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

SYDev

[풀스택서비스프로그래밍] Lecture 01. Dart 언어의 이해(심화) - part1 본문

3학년 2학기 전공/풀스택서비스프로그래밍

[풀스택서비스프로그래밍] Lecture 01. Dart 언어의 이해(심화) - part1

시데브 2024. 9. 16. 20:23
728x90
경희대학교 이성원 교수님의 풀스택 서비스 프로그래밍 수업을 기반으로 정리한 글입니다.

 

Class 직접 만들기 Part 1

  • 기본적인 개념은 c++과 유사
late
- Null-safety에 의해 null 값을 가질 수 없는 변수에 대해 -> "일부러 지금 초기화하지 않고, 나중에 초기화 하겠다"를 선언하는 문법
  • constructor
    • 클래스 객체 생성 최초 시점 호출되는 함수(메소드)
    • 클래스 이름과 메소드의 이름 동일
    • 리턴 값 X
  • getter, setter
    • get/set 유형 메소드를 만드는 문법
    • ex) String get asString => "$_value" -> value 값을 string으로 변환하여 반환하는 asString이란 이름을 가진 getter
    • ex) set value(int givenValue) => _value = givenValue -> _value 값을 givenValue로 변환해주는 value라는 이름을 가진 setter
    • get/set 유형은 값을 꺼내거나, 저장하는 public methods의 유형
  • operator overloading
  • 유전의 법칙(sub-class, inheritance)
    • extends 문법 사용
    • Base class를 override할 때, 명시적으로 @override 사용
    • 프로그래밍 언어의 계열은 static, dynamic 둘로 나눠짐 
      • static -> dart
      • dynamic -> python
class DERIVED-CLASS extends BASE-CLASS {
}

@override 
void overrideMethod(int givneValue) {
}

 

 

Class 직접 만들기 Part 2

  • mixin 클래스
    • 사실상 class이나 객체가 되어 사용되기 보다는, 다른 class의 부속품으로 사용되는 class
    • class 문법 대신 mixin 문법 사용
  • #include <iostream> -> iostream.h 파일을 open하여, 모든 line을 copy한 후 현재 위치에 paste함
    • class TimemachineInterger extends Integer with ActivationFlag { -> Integer를 기본으로 paste하고, 그 위에 ActivationFlag를 덮어씀
  • mixin ActivationFlag on TimemachineInteger -> on 문법으로 mixin을 특정 class에만 적용할 수도 있음
mixin ActivationFlag {
    bool_flag = true;
    
    bool get activated => _flag;
    set activated(bool givenFlag) => (_flag = givenFlag);
}

class TimemachineInterger extends Integer with ActivationFlag {

 

다중 상속의 문제점

  • The diamond problem -> multiple base classes에 모두 같은 이름을 가진 method가 선언되어 있을 때, derived class에서는 해당 method를 호출할 때, 어떤 base class의 method를 호출할지 모호해짐 -> base class와 IS-A relation이 모호해짐

 

Class 직접 만들기 Part 3

  • abstract 클래스
    • 객체를 만들 수 없는 Base 클래스
    • Derived 클래스에 공통적인 data 'method type'만 정의
  • implements 문법을 사용해서 derived class 생성
abstract class Rectangle {
    int cx = 0, cy = 0;
    void draw();
}

class Circle implements Rectangle {
    @override
    int cx = 0, cy = 0;
    
    late int radius;
    
    @override
    void draw() {
        print("> Circle.draw(): center($cx, $cy) with r[$radius]");
    }
    
    Circle([int givenRadius = 1]) : radius = givenRadius;
}

 

Class 직접 만들기 Part 4

  • Template<T>
  • Template<T, Y>

 

+

  • base 문법
    • base 클래스 수정자로 정의한 클래스는, 해당 클래스가 속한 라이브러리 외부에서 implement하는 것을 금지, 하지만 extend는 가능
  • interface 
    • implement는 가능, extend는 불가능
  • abstract interface
    • abstract 수정자와 interface 수정자 동시 사용 
    • pure interface -> 이렇게 정의한 class는 스스로 객체화 불가능, 오로지 다른 class에서 implements하여 만들어지는 재료 역할만 수행
  • final
    • 사용만 가능, extends 혹은 implements 금지

 

Multi-core

중앙 처리 장치(CPU)
- 컴퓨터 시스템을 통제하고 프로그램의 연산을 실행, 처리하는 가장 핵심적인 컴퓨터의 제어 장치 혹은 그 기능을 내장한 칩

코어
- 중앙 처리 장치의 역할을 하는 블록
- 예전에는 하나의 cpu 안에 한 개의 core 구조를 가진 싱글 코어가 다수였지만, 최근에는 한 개의 칩 안에 여러 개의 코어를 가지는 멀티코어 구조를 채택

멀티코어
- 한 개의 칩 안에 여러 개의 연산을 처리할 수 있는 장치를 병렬적으로 연결한 구조
- 멀티코어를 활용할 수 있도록 코딩해야 멀티코어 CPU를 제대로 활용할 수 있다.

Performance Core
- physically larger, high-performance cores
- high clock speeds and Hyper-Threading capabilities

Efficient Core
- physically smaller, high CPU efficiency
- consume significantly less power
- hyper threading 제공 X

 

Multi-processing

Multi-processing
- process vs thread -> process는 서로의 메모리 공유(독립적으로 수행) , thread는 같은 프로세스 내에서 "특정 메모리" 공유
-> thread는 process에 할당된 가상메모리 중 Heap, Data, Code(literals, instructions) 영역 공유, but Stack영역, program counter register는 공유 X (thread마다 따로 할당)
multi-processing:한 컴퓨터 내 2개 이상의 프로세서(CPU)들이 같은 작업 내 2개 이상의 서로 다른 부분을 동시에(parallel) 처리할 수 있는 프로그램
Multi-threading
multi-threading: 한 process 내에서 여러 thread를 생성할 수 있는 프로그램, 여러 thread는 독립적으로 수행되지만 process의 자원을 공유하며 동시에($) 함께 수행됨

Multi-processing vs Multi-threading
concurrency: 같은 시간에 많은 작업을 처리 
대기 시간을 숨기며 동시에 작업이 처리되는 것처럼 보이는 illusion을 일으킴
-> 한 시점에 한 가지 작업만 처리하지만, 여러 작업이 동시에 수행되게끔 착각을 불러일으킴
Parallelism: 실제로 같은 시간에 여러 작업을 동시에 처리 -> 속도를 높이는 목적

 

C compiler. Memory map. Program in RAM

  • rodata: program code(functions, methods) -> read only
  • data: constant, 전역변수, 정적변수
  • bss: 초기화되지 않은 전역, 정적변수 -> 변수 초기화하지 않을 시에 이 부분을 차지

 

 

 


참고자료

 

자바와 다중상속 문제

다른 객체지향언어인 C++에서는 여러 조상 클래스로부터 상속받는 것이 가능한 '다중상속(multiple inheritance)' 을 허용하지만 자바에서는 오직 단일 상속만을 허용합니다. 사실 다중상속 문제는 수

castlejune.tistory.com

 

Where will the Initialized data segment values are stored before run time?

Normally the data segment in C code resides in the RAM volatile memory and consists of Initialized data segment, Uninitialized data segment(.BSS), Stack memory and the heap. Stack memory is only c...

stackoverflow.com

 

728x90