1
00:00:00,000 --> 00:00:02,300
When should you repeat code?

2
00:00:02,300 --> 00:00:05,480
I merged two discounts into one helper.

3
00:00:05,480 --> 00:00:08,800
A promo cap just cut my employee benefits.

4
00:00:08,980 --> 00:00:11,340
DRY means Don’t Repeat Yourself.

5
00:00:11,340 --> 00:00:13,520
Share a rule, not just matching code.

6
00:00:13,520 --> 00:00:17,060
Here, the promo cap went into the helper both discounts called.

7
00:00:17,240 --> 00:00:21,640
So should I repeat myself, or use a factory?

8
00:00:21,820 --> 00:00:25,280
WET is often expanded as Write Everything Twice.

9
00:00:25,280 --> 00:00:27,200
Here, keep two small functions

10
00:00:27,200 --> 00:00:29,470
so independent rules can change separately.

11
00:00:29,470 --> 00:00:31,180
Only the promo gets the cap.

12
00:00:31,360 --> 00:00:33,160
A factory is another option.

13
00:00:33,160 --> 00:00:36,360
It returns a discount function with its own rate and cap.

14
00:00:36,360 --> 00:00:37,960
Infinity means no cap.

15
00:00:37,960 --> 00:00:40,880
Reuse the math, configure the policies separately.

16
00:00:41,060 --> 00:00:43,520
Both designs give $100 off for employees,

17
00:00:43,520 --> 00:00:44,840
$25 with the promo.

18
00:00:44,840 --> 00:00:46,440
Choose simple separate rules,

19
00:00:46,440 --> 00:00:48,960
or a factory when the shared calculation is stable.

20
00:00:48,960 --> 00:00:50,340
Test both policies.

21
00:00:50,520 --> 00:00:52,840
I saved two lines.

22
00:00:52,840 --> 00:00:55,240
Lost $75.

23
00:00:55,240 --> 00:00:58,200
Management called it a performance improvement.
