Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
140
이펙티브 러스트
아이템
13
: 디폴트 구현을 사용해 필수 트레이트 메서드를 최소화
하라
트레이트를 설계할 때는 트레이트를 구현하는 프로그래머(구현자 )와 트레이트를 활용하는 프
로그래머 (사용자)라는 두 종류의 사용자를 고려해야 한다. 트레이트 설계가 어려운 이유 중
하나는 바로 두 사용자의 요구 사항이 서로 상반되기 때문이다.
구현자의 편의를 위해서는 목적 달성에 필요한 최소한의 메서드만 트레이트에 두는 것이 좋다.
활용자의 편의를 위해서는 해당 트레이트를 사용할 수 있는 주된 방법을 모두 포괄하도록 메서드를 다양
하게 제공하는 것이 좋다.
이렇게 상충된 요구 사항을 균형 있게 반영하려면 사용자의 편의를 위해 메서드를 다양하게 제
공하는 동시에, 인터페이스에서 제공하는 메서드 중에서도 기본적인 연산으로도 만들 수 있도
록 디폴트 구현을 제공하면 된다.
이에 대한 간단한 예로 반복할 항목 수를 알고 있는
Iterator
ExactSizeIterator
에 정의
is
_
empty
()
메서드가 있다.
8
이 메서드의 디폴트 구현은 다음과 같이 트레이트 메서드인
len
()
기반으로 구현돼 있다.
fn is_empty(&self) -> bool {
self.len() == 0
}
디폴트 구현은 어디까지나 디폴트일 뿐이다. 해당 트레이트 구현에서 반복자가 비어 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169212946