1 00:00:00,720 --> 00:00:06,810 In this video, we are going to talk about the decorated pattern, which has the scope to add new functionality 2 00:00:06,930 --> 00:00:09,280 to an object without affecting its structure. 3 00:00:10,640 --> 00:00:16,070 This pattern creates a decorator class, which wraps the original class and provides additional functional 4 00:00:16,070 --> 00:00:18,950 beekeeping class method signature untouched. 5 00:00:21,330 --> 00:00:27,180 The decorator adheres to the single responsibility principle, which states that each object should 6 00:00:27,180 --> 00:00:31,260 have the responsibility of a single part of the functionality of a software. 7 00:00:32,490 --> 00:00:36,150 In other words, a class should do only one thing and two well. 8 00:00:38,030 --> 00:00:43,340 To achieve this decorator's use of principles like inheritance and composition. 9 00:00:44,710 --> 00:00:46,450 Let's a look at the following diagram. 10 00:00:48,280 --> 00:00:53,590 The component class is usually the abstraction, which can be either an interface or an abstract class. 11 00:00:55,120 --> 00:00:57,730 This class is implemented by the concrete component. 12 00:00:59,430 --> 00:01:02,900 As you may have guessed, the concrete component will be decorated. 13 00:01:03,850 --> 00:01:09,520 The decorating class will be inheriting the same component interface in order to make it similar to 14 00:01:09,520 --> 00:01:12,340 the concrete object that is being decorated. 15 00:01:13,720 --> 00:01:17,080 Below, we can have multiple complete decorator's for the same object. 16 00:01:18,850 --> 00:01:24,610 One of the weaknesses of this pattern can be the fact that a new class will be required by each new 17 00:01:24,610 --> 00:01:27,190 feature, which will increase the volume of the code. 18 00:01:28,740 --> 00:01:31,470 Let's have a look on how all this looks in code.