[Dart/Linter] Dart Singleton 클래스 형식 > Node/Flutter/Dart

본문 바로가기

사이트 내 전체검색

Node/Flutter/Dart

[Dart/Linter] Dart Singleton 클래스 형식

작성일 23-01-08 20:22

페이지 정보

작성자sbLAB 조회 3,028회 댓글 0건

본문

[Linter 참고]

Dart 는 변수명에 언더스코어(_) 붙혀(_instanceprivate 을 정의하고, IDE툴은 private 에 대해 final 제안.

private / final =>  _instance  

public =>  instance   

https://dart-lang.github.io/linter/lints/prefer_final_fields.html 



UserInfoModelRepository  Singleton 클래스 만들기 


1) 컨트롤러등에서 데이타 변경필요한 경우 

※  final   _instance  => instance 


class UserInfoModelRepository {

static UserInfoModelRepository instance = UserInfoModelRepository._internal();

factory UserInfoModelRepository() {
return instance;
}

UserInfoModelRepository._internal();
} 


2) 데이타 변경 없거나, 변경되면 안되는 경우 

※  final   instance  =>  _instance [권장 Linter Rules]   


class UserInfoModelRepository {

static final UserInfoModelRepository _instance = UserInfoModelRepository._internal();

factory UserInfoModelRepository() {
return _instance;
}

UserInfoModelRepository._internal();
} 


댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기