Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +9 -0
- 100 - GPT + Slack + Jira + Gmail Integration/001 GPT + Slack + Jira Integration Work with Jira Datasource.mp4 +3 -0
- 102 - DALL-E - Text to image AI Model by OpenAI/001 DALL-E Model & API Overview With Examples in Postman.mp4 +3 -0
- 103 - Whisper - Speech to text AI model by OpenAI/001 Whisper Model & API Overview With Examples in Postman.mp4 +3 -0
- 104 - UML Introduction/001 Introduction to UML.mp4 +3 -0
- 105 - Behavioral Diagrams/001 Use Case Diagram.mp4 +3 -0
- 105 - Behavioral Diagrams/002 Sequence Diagram.mp4 +3 -0
- 105 - Behavioral Diagrams/003 Activity Diagram.mp4 +3 -0
- 105 - Behavioral Diagrams/004 State Machine Diagram.mp4 +3 -0
- 105 - Behavioral Diagrams/005 Communication Diagram (formerly known as Collaboration Diagram).mp4 +3 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/005 YAGNI Principle in OOP_en.srt +1216 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/006 DRY Principle in OOP Part 1_en.srt +908 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/007 Source-code-examples-shown-in-the-lesson.url +2 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/008 Packaging Pricniples p.1 Cohesion Principles_en.srt +1112 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/009 Packaging Pricniples p.2 Coupling Principles and Others_en.srt +1320 -0
- 38 - Object-oriented Architecture, Clean Code Design (Advanced)/external-links.txt +15 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/001 GoF Patterns Overview_en.srt +744 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/002 Creational Patterns_en.srt +1688 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/002 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/003 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/003 Structural Patterns, p.1_en.srt +1604 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/004 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/004 Structural Patterns, p.2_en.srt +1144 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/005 Behevioral Patterns, p.1_en.srt +1688 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/005 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/006 Behevioral Patterns, p.2_en.srt +1636 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/006 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/007 Behevioral Patterns, p.3_en.srt +1100 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/007 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 39 - GoF Design Patterns of Software Architecture in OOP/external-links.txt +18 -0
- 40 - ===== Design Patterns Interview Questions =====/001 Part 1 OOP & Design Patterns Interview - Questions and Answers.html +69 -0
- 41 - I18N & L10N/001 [Part 1] Localization and Internationalization_en.srt +588 -0
- 41 - I18N & L10N/002 Source-code-examples-from-the-lesson.url +2 -0
- 41 - I18N & L10N/002 [Part 2] Localization and Internationalization_en.srt +872 -0
- 41 - I18N & L10N/external-links.txt +3 -0
- 42 - ===== Java Core Interview Preparation =====/001 How to be prepared for the interview.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/002 Part 1 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/003 Part 2 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/004 Part 3 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/005 Part 4 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/006 Part 5 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/007 Part 6 Java Core Interview Questions and Answers.html +69 -0
- 42 - ===== Java Core Interview Preparation =====/008 Part 7 Java Core Interview Questions and Answers.html +69 -0
- 43 - == EXAM Java Standard Edition - Online Store - Task description and solution ==/001 Implement online store application.html +69 -0
- 44 - Java New Versions/001 Java 8 Features (Lambda, Stream API, Optional, Effectively Final, etc.)_en.srt +1644 -0
- 44 - Java New Versions/001 Source-code-example-from-the-lesson.url +2 -0
- 44 - Java New Versions/002 Java 9 Stream API Updates, Multi-Resolution Image, Stack-Walking API, etc_en.srt +960 -0
- 44 - Java New Versions/002 Source-code-example-from-the-lesson.url +2 -0
- 44 - Java New Versions/003 Java 9 Process API & CompletableFuture API updates, Interface Private Methods_en.srt +800 -0
- 44 - Java New Versions/003 Source-code-example-from-the-lesson.url +2 -0
.gitattributes
CHANGED
|
@@ -80,3 +80,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 80 |
10[[:space:]]-[[:space:]]Methods[[:space:]]in[[:space:]]Java/016[[:space:]]Homework[[:space:]]review[[:space:]]Methods.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 81 |
101[[:space:]]-[[:space:]]Manage[[:space:]]a[[:space:]]Scrum[[:space:]]Team[[:space:]]with[[:space:]]ChatGPT/001[[:space:]]Managing[[:space:]]Scrum[[:space:]]&[[:space:]]Risk[[:space:]]Management[[:space:]]with[[:space:]]Custom[[:space:]]Bot,[[:space:]]Slack[[:space:]]&[[:space:]]GPT.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 82 |
100[[:space:]]-[[:space:]]GPT[[:space:]]+[[:space:]]Slack[[:space:]]+[[:space:]]Jira[[:space:]]+[[:space:]]Gmail[[:space:]]Integration/002[[:space:]]Generate[[:space:]]Tickets[[:space:]]in[[:space:]]Jira[[:space:]]&[[:space:]]Send[[:space:]]Email[[:space:]]from[[:space:]]Slack[[:space:]]via[[:space:]]Chat[[:space:]]Interface.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
10[[:space:]]-[[:space:]]Methods[[:space:]]in[[:space:]]Java/016[[:space:]]Homework[[:space:]]review[[:space:]]Methods.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 81 |
101[[:space:]]-[[:space:]]Manage[[:space:]]a[[:space:]]Scrum[[:space:]]Team[[:space:]]with[[:space:]]ChatGPT/001[[:space:]]Managing[[:space:]]Scrum[[:space:]]&[[:space:]]Risk[[:space:]]Management[[:space:]]with[[:space:]]Custom[[:space:]]Bot,[[:space:]]Slack[[:space:]]&[[:space:]]GPT.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 82 |
100[[:space:]]-[[:space:]]GPT[[:space:]]+[[:space:]]Slack[[:space:]]+[[:space:]]Jira[[:space:]]+[[:space:]]Gmail[[:space:]]Integration/002[[:space:]]Generate[[:space:]]Tickets[[:space:]]in[[:space:]]Jira[[:space:]]&[[:space:]]Send[[:space:]]Email[[:space:]]from[[:space:]]Slack[[:space:]]via[[:space:]]Chat[[:space:]]Interface.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
100[[:space:]]-[[:space:]]GPT[[:space:]]+[[:space:]]Slack[[:space:]]+[[:space:]]Jira[[:space:]]+[[:space:]]Gmail[[:space:]]Integration/001[[:space:]]GPT[[:space:]]+[[:space:]]Slack[[:space:]]+[[:space:]]Jira[[:space:]]Integration[[:space:]]Work[[:space:]]with[[:space:]]Jira[[:space:]]Datasource.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
104[[:space:]]-[[:space:]]UML[[:space:]]Introduction/001[[:space:]]Introduction[[:space:]]to[[:space:]]UML.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
102[[:space:]]-[[:space:]]DALL-E[[:space:]]-[[:space:]]Text[[:space:]]to[[:space:]]image[[:space:]]AI[[:space:]]Model[[:space:]]by[[:space:]]OpenAI/001[[:space:]]DALL-E[[:space:]]Model[[:space:]]&[[:space:]]API[[:space:]]Overview[[:space:]]With[[:space:]]Examples[[:space:]]in[[:space:]]Postman.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
103[[:space:]]-[[:space:]]Whisper[[:space:]]-[[:space:]]Speech[[:space:]]to[[:space:]]text[[:space:]]AI[[:space:]]model[[:space:]]by[[:space:]]OpenAI/001[[:space:]]Whisper[[:space:]]Model[[:space:]]&[[:space:]]API[[:space:]]Overview[[:space:]]With[[:space:]]Examples[[:space:]]in[[:space:]]Postman.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
105[[:space:]]-[[:space:]]Behavioral[[:space:]]Diagrams/001[[:space:]]Use[[:space:]]Case[[:space:]]Diagram.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
105[[:space:]]-[[:space:]]Behavioral[[:space:]]Diagrams/002[[:space:]]Sequence[[:space:]]Diagram.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
105[[:space:]]-[[:space:]]Behavioral[[:space:]]Diagrams/003[[:space:]]Activity[[:space:]]Diagram.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
105[[:space:]]-[[:space:]]Behavioral[[:space:]]Diagrams/004[[:space:]]State[[:space:]]Machine[[:space:]]Diagram.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
105[[:space:]]-[[:space:]]Behavioral[[:space:]]Diagrams/005[[:space:]]Communication[[:space:]]Diagram[[:space:]](formerly[[:space:]]known[[:space:]]as[[:space:]]Collaboration[[:space:]]Diagram).mp4 filter=lfs diff=lfs merge=lfs -text
|
100 - GPT + Slack + Jira + Gmail Integration/001 GPT + Slack + Jira Integration Work with Jira Datasource.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74f6944cafe9f7048f386c0ff9c7ec5cd16cee22c820bea99e090a4580da64c3
|
| 3 |
+
size 548747142
|
102 - DALL-E - Text to image AI Model by OpenAI/001 DALL-E Model & API Overview With Examples in Postman.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bc49650f24e918b82f295ef291526f2583d11b8c6674b1d84dc92963ed294161
|
| 3 |
+
size 328175978
|
103 - Whisper - Speech to text AI model by OpenAI/001 Whisper Model & API Overview With Examples in Postman.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19ee849895a8b89954fadf21ad96329a8eb9553c741aeec40aac21821a8bd98f
|
| 3 |
+
size 279486114
|
104 - UML Introduction/001 Introduction to UML.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:97e141fa986e93b6eb91ef5e731a81f458e60f4c2039762d256021dbd8a79323
|
| 3 |
+
size 212221548
|
105 - Behavioral Diagrams/001 Use Case Diagram.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4191cabdacc1f89a646a134acb59ad35a1303e077d78f9a152d8d31133d6330f
|
| 3 |
+
size 242670222
|
105 - Behavioral Diagrams/002 Sequence Diagram.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd23a7644d13e525b0f61c9cf6d498046628d1d60a28db0827983a2c6cf073b7
|
| 3 |
+
size 146030394
|
105 - Behavioral Diagrams/003 Activity Diagram.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ea420fcf39a85c286b339ce8c1bfc05a1b0e5e3f5b58b2d66f9c8d96f03cb4f
|
| 3 |
+
size 231164055
|
105 - Behavioral Diagrams/004 State Machine Diagram.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7daa888d1b4ad85dd55e118f1e82b07d721e3bd6f4e02cd032277da167623e8
|
| 3 |
+
size 232694435
|
105 - Behavioral Diagrams/005 Communication Diagram (formerly known as Collaboration Diagram).mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9afd530a221de4ff5bbf8213d3fe2966fffdbef6557dabfa4b3f6e6b33f0a95c
|
| 3 |
+
size 191440284
|
38 - Object-oriented Architecture, Clean Code Design (Advanced)/005 YAGNI Principle in OOP_en.srt
ADDED
|
@@ -0,0 +1,1216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello team!
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:10,000
|
| 7 |
+
In this lesson we are going to learn Yagi principle.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:10,000 --> 00:00:15,000
|
| 11 |
+
Today we'll delve into the essential aspects of the you aren't gonna need it principle.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:15,000 --> 00:00:22,000
|
| 15 |
+
We'll start by defining what the agony Principle entails, exploring its core philosophy and how it
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:24,000
|
| 19 |
+
applies to software development practices.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:25,000 --> 00:00:30,000
|
| 23 |
+
Next, we'll discuss the compelling benefits of embracing Yagi yarn in your projects, highlighting
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:35,000
|
| 27 |
+
how it reduces unnecessary complexity and optimizes resource allocation.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:36,000 --> 00:00:42,000
|
| 31 |
+
Moving forward, we'll explore practical strategies on how to effectively apply yazhini in real world
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:42,000 --> 00:00:47,000
|
| 35 |
+
scenarios, emphasizing iterative development and focusing on immediate user needs.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:48,000 --> 00:00:54,000
|
| 39 |
+
Following that, we'll examine insightful case studies that showcase the successful implementation of
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:54,000 --> 00:00:57,000
|
| 43 |
+
the Yagni principle in various software projects.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:58,000 --> 00:01:06,000
|
| 47 |
+
These examples will illustrate its impact on enhancing agility, maintaining code simplicity, and delivering
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:06,000 --> 00:01:07,000
|
| 51 |
+
value driven solutions.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:08,000 --> 00:01:15,000
|
| 55 |
+
Moreover, we'll provide concrete code examples that demonstrate the application of yakhni, illustrating
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:15,000 --> 00:01:21,000
|
| 59 |
+
how to streamline code bases by prioritizing essential functionalities and avoiding premature optimizations
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:22,000 --> 00:01:24,000
|
| 63 |
+
to enrich our understanding.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:24,000 --> 00:01:30,000
|
| 67 |
+
We will compare the Yanai principle with another fundamental concept in software development keep it
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:30,000 --> 00:01:31,000
|
| 71 |
+
simple, stupid principle.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:32,000 --> 00:01:37,000
|
| 75 |
+
We'll highlight the key differences between these principles, emphasizing their distinct approaches
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:37,000 --> 00:01:43,000
|
| 79 |
+
to achieving simplicity and efficiency in software design and implementation.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:43,000 --> 00:01:50,000
|
| 83 |
+
By the end of this session, you'll gain a comprehensive grasp of the Yogini principles, significance,
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:50,000 --> 00:01:56,000
|
| 87 |
+
and practical implementation strategies, equipping you with insights to enhance your software development
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:56,000 --> 00:01:57,000
|
| 91 |
+
practices.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:57,000 --> 00:02:05,000
|
| 95 |
+
Let's dive in and explore how yogini can optimize your project workflows and drive impactful results.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:05,000 --> 00:02:07,000
|
| 99 |
+
So let's start our lesson.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:08,000 --> 00:02:14,000
|
| 103 |
+
The unit principle, which stands for you aren't gonna need it, is a fundamental tenet in software
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:14,000 --> 00:02:21,000
|
| 107 |
+
development, particularly within the practices of extreme programming and agile methodologies.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:21,000 --> 00:02:28,000
|
| 111 |
+
It emphasizes simplicity and encourages developers to avoid adding functionality until it is necessary.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:29,000 --> 00:02:37,000
|
| 115 |
+
The core idea is to minimize unnecessary complexity and effort by focusing only on the immediate requirements
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:37,000 --> 00:02:38,000
|
| 119 |
+
of the project.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:39,000 --> 00:02:46,000
|
| 123 |
+
The principle was introduced by Ron Jeffries, one of the original proponents of extreme programming.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:46,000 --> 00:02:52,000
|
| 127 |
+
Extreme programming is an agile software development methodology that focuses on improving software
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:52,000 --> 00:02:59,000
|
| 131 |
+
quality and responsiveness to changing customer requirements through frequent releases in short development
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:59,000 --> 00:03:05,000
|
| 135 |
+
cycles, which improves productivity and introduces checkpoints where new customer requirements can
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:05,000 --> 00:03:06,000
|
| 139 |
+
be adopted.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:07,000 --> 00:03:14,000
|
| 143 |
+
Beyond extreme programming, Unai has influenced other agile methodologies and is widely embraced in
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:14,000 --> 00:03:15,000
|
| 147 |
+
agile practices.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:15,000 --> 00:03:22,000
|
| 151 |
+
It supports the agile values of simplicity, customer collaboration, and responding to change.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:23,000 --> 00:03:29,000
|
| 155 |
+
Yanai is now considered a best practice in modern software development, reinforcing principles like
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:29,000 --> 00:03:33,000
|
| 159 |
+
lean programming, which aims to minimize waste and maximize value.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:34,000 --> 00:03:40,000
|
| 163 |
+
Let's now address another important question why we need to use this principle?
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:40,000 --> 00:03:44,000
|
| 167 |
+
What benefits do we expect to get from using this principle?
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:44,000 --> 00:03:50,000
|
| 171 |
+
There are four critical costs in software development that are significantly influenced by adherence
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:50,000 --> 00:03:52,000
|
| 175 |
+
to the you aren't gonna need it principle.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:53,000 --> 00:03:53,000
|
| 179 |
+
They are.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:54,000 --> 00:03:55,000
|
| 183 |
+
Cost of build.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:55,000 --> 00:03:56,000
|
| 187 |
+
Cost of delay.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:57,000 --> 00:03:58,000
|
| 191 |
+
Cost of carry.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:58,000 --> 00:03:59,000
|
| 195 |
+
Cost of repair.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:00,000 --> 00:04:06,000
|
| 199 |
+
By prioritizing essential functionalities and deferring non-critical decisions until necessary.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:06,000 --> 00:04:11,000
|
| 203 |
+
Jain aims to minimize waste and maximize value for users and stakeholders.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:12,000 --> 00:04:18,000
|
| 207 |
+
To answer the question why we need to use this principle, we need to understand how Jargony principle
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:18,000 --> 00:04:21,000
|
| 211 |
+
may impact these four costs.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:22,000 --> 00:04:24,000
|
| 215 |
+
Let me explain you in details.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:25,000 --> 00:04:26,000
|
| 219 |
+
Cost of building.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:26,000 --> 00:04:32,000
|
| 223 |
+
The cost of building includes all resources invested in developing a feature or solution.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:32,000 --> 00:04:38,000
|
| 227 |
+
This includes time spent on planning, coding, testing and other development activities.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:38,000 --> 00:04:46,000
|
| 231 |
+
When developers adhere to Vianai, they focus only on implementing features that are currently necessary.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:47,000 --> 00:04:53,000
|
| 235 |
+
By avoiding speculative features, they minimize the amount of resources expended on functionalities
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:53,000 --> 00:05:00,000
|
| 239 |
+
that may never be used, or that could change significantly before implementation.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:01,000 --> 00:05:02,000
|
| 243 |
+
Cost of delay.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:02,000 --> 00:05:09,000
|
| 247 |
+
The cost of delay refers to the missed opportunities or economic impact of not delivering a feature
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:09,000 --> 00:05:10,000
|
| 251 |
+
promptly.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:10,000 --> 00:05:18,000
|
| 255 |
+
If developers prioritize less critical features over more important ones, they risk delaying the delivery
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:18,000 --> 00:05:21,000
|
| 259 |
+
of value to users or stakeholders.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:21,000 --> 00:05:28,000
|
| 263 |
+
Yang encourages developers to deliver the most essential features quickly, ensuring that valuable functionalities
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:28,000 --> 00:05:31,000
|
| 267 |
+
are implemented promptly without unnecessary delays.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:32,000 --> 00:05:34,000
|
| 271 |
+
Cost of carry.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:34,000 --> 00:05:41,000
|
| 275 |
+
The cost of carry relates to the ongoing challenges and additional work caused by maintaining and managing
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:41,000 --> 00:05:43,000
|
| 279 |
+
specific features within the software.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:43,000 --> 00:05:50,000
|
| 283 |
+
When unnecessary or overly complex features are implemented, they can increase the overall complexity
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:50,000 --> 00:05:51,000
|
| 287 |
+
of the code base.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:51,000 --> 00:05:59,000
|
| 291 |
+
This complexity makes it more difficult to maintain, debug, and enhance other parts of the software.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:59,000 --> 00:06:07,000
|
| 295 |
+
JNI helps mitigate the cost of carry by promoting simplicity and avoiding unnecessary complexity, thus
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:07,000 --> 00:06:11,000
|
| 299 |
+
reducing the long term burden on development efforts.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:12,000 --> 00:06:13,000
|
| 303 |
+
Cost of repair.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:13,000 --> 00:06:14,000
|
| 307 |
+
Technical debt.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:15,000 --> 00:06:21,000
|
| 311 |
+
The cost of repair, often referred to as technical debt, is incurred when suboptimal decisions or
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:21,000 --> 00:06:24,000
|
| 315 |
+
shortcuts are made during development.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:25,000 --> 00:06:31,000
|
| 319 |
+
If developers implement features that later require significant adjustments, fixing and maintaining
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:31,000 --> 00:06:35,000
|
| 323 |
+
those features becomes more costly over time.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:35,000 --> 00:06:42,000
|
| 327 |
+
Yanai encourages developers to avoid premature optimization and overengineering, which can lead to
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:42,000 --> 00:06:49,000
|
| 331 |
+
technical debt by focusing on immediate needs and deferring decisions about future features until they
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:49,000 --> 00:06:50,000
|
| 335 |
+
are truly required.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:50,000 --> 00:06:55,000
|
| 339 |
+
Developers minimize the likelihood of accruing technical debt.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:55,000 --> 00:07:01,000
|
| 343 |
+
Just a quick note in case you will have any questions during the lesson, please don't wait till the
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:01,000 --> 00:07:02,000
|
| 347 |
+
end of the lesson.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:02,000 --> 00:07:06,000
|
| 351 |
+
Just post your question below the video and I will be happy to answer.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:07,000 --> 00:07:14,000
|
| 355 |
+
Let's continue and let me now elaborate on the benefits we can expect to gain from using this principle.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:15,000 --> 00:07:21,000
|
| 359 |
+
Using the yagna principle offers several significant benefits in software development, primarily revolving
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:21,000 --> 00:07:25,000
|
| 363 |
+
around efficiency, simplicity, and responsiveness.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:26,000 --> 00:07:33,000
|
| 367 |
+
Let's review in details why developers and teams should use yagna and the benefits it provides.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:34,000 --> 00:07:35,000
|
| 371 |
+
Simplified code base.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:36,000 --> 00:07:40,000
|
| 375 |
+
A smaller, simpler code base is easier to maintain.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:40,000 --> 00:07:47,000
|
| 379 |
+
There are fewer bugs, and it's easier to spot and fix issues by not adding unnecessary features.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:47,000 --> 00:07:55,000
|
| 383 |
+
You minimize technical debt, which is the cost of additional rework caused by choosing an easy solution
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:55,000 --> 00:07:58,000
|
| 387 |
+
now instead of a better approach that would take longer.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:59,000 --> 00:08:01,000
|
| 391 |
+
Increased productivity.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:02,000 --> 00:08:08,000
|
| 395 |
+
Developers can work more efficiently by concentrating on immediate tasks, leading to higher productivity
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:08,000 --> 00:08:11,000
|
| 399 |
+
and a more streamlined development process.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:12,000 --> 00:08:17,000
|
| 403 |
+
Completing and delivering smaller increments of functionality more quickly keeps the team motivated
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:17,000 --> 00:08:19,000
|
| 407 |
+
and stakeholders satisfied.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:20,000 --> 00:08:27,000
|
| 411 |
+
Enhanced quality with fewer features to test the testing process can be more rigorous and thorough,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:27,000 --> 00:08:29,000
|
| 415 |
+
leading to higher quality software.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:30,000 --> 00:08:35,000
|
| 419 |
+
By not implementing speculative features, the potential for introducing bugs is reduced.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:37,000 --> 00:08:42,000
|
| 423 |
+
Better responsiveness to change yarn allows for greater adaptability.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:42,000 --> 00:08:49,000
|
| 427 |
+
As customer needs evolve, the team can more easily shift focus and make necessary changes without being
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:49,000 --> 00:08:51,000
|
| 431 |
+
bogged down by unused features.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:52,000 --> 00:08:58,000
|
| 435 |
+
Teams can continuously refine and improve the software based on actual user feedback and requirements,
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:58,000 --> 00:09:00,000
|
| 439 |
+
rather than assumptions.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:01,000 --> 00:09:02,000
|
| 443 |
+
Cost efficiency.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:03,000 --> 00:09:08,000
|
| 447 |
+
Focusing only on necessary features means fewer resources spent on development.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:08,000 --> 00:09:11,000
|
| 451 |
+
This can result in significant cost savings.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:12,000 --> 00:09:18,000
|
| 455 |
+
Resources can be allocated more effectively, prioritizing the development of features that provide
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:18,000 --> 00:09:19,000
|
| 459 |
+
immediate value.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:20,000 --> 00:09:26,000
|
| 463 |
+
Increased customer satisfaction by focusing on what customers currently need.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:26,000 --> 00:09:33,000
|
| 467 |
+
Teams ensure that the delivered software meets user expectations and provides tangible benefits.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:33,000 --> 00:09:39,000
|
| 471 |
+
Regularly delivering functional increments keeps customers engaged and allows for constant feedback,
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:39,000 --> 00:09:43,000
|
| 475 |
+
which helps in aligning the product with user needs.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:44,000 --> 00:09:47,000
|
| 479 |
+
How you can start applying Yang principles starting from today.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:47,000 --> 00:09:55,000
|
| 483 |
+
Already applying the you aren't gonna need it principle effectively involves adopting a mindset and
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:55,000 --> 00:10:02,000
|
| 487 |
+
implementing specific practices to ensure that software development remains focused, efficient, and
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:02,000 --> 00:10:04,000
|
| 491 |
+
responsive to current requirements.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:05,000 --> 00:10:08,000
|
| 495 |
+
Here is a detailed guide on how to apply yanyi in practice.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:09,000 --> 00:10:11,000
|
| 499 |
+
Focus on essential features.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:12,000 --> 00:10:15,000
|
| 503 |
+
Start with minimum viable product MVP.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:15,000 --> 00:10:22,000
|
| 507 |
+
Define and prioritize the core functionalities that are essential for the initial release of the product.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:22,000 --> 00:10:28,000
|
| 511 |
+
These are features that directly address the primary needs and provide immediate value to users.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:29,000 --> 00:10:31,000
|
| 515 |
+
Avoid speculative features.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:31,000 --> 00:10:37,000
|
| 519 |
+
Resist the temptation to implement features that are not explicitly required by current user stories
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:37,000 --> 00:10:38,000
|
| 523 |
+
or business objectives.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:39,000 --> 00:10:43,000
|
| 527 |
+
Stay focused on what is essential to meet the current iteration's goals.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:44,000 --> 00:10:46,000
|
| 531 |
+
Embrace incremental development.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:47,000 --> 00:10:50,000
|
| 535 |
+
Develop software in small, manageable increments.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:51,000 --> 00:10:55,000
|
| 539 |
+
Each increment should deliver tangible value and be fully functional.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:56,000 --> 00:10:59,000
|
| 543 |
+
Seek frequent feedback from stakeholders and end users.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:59,000 --> 00:11:05,000
|
| 547 |
+
Use this feedback to validate assumptions and adjust priorities accordingly, ensuring that subsequent
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:05,000 --> 00:11:10,000
|
| 551 |
+
increments reflect real needs rather than imagined future requirements.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:11,000 --> 00:11:12,000
|
| 555 |
+
Refactor and simplify.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:12,000 --> 00:11:19,000
|
| 559 |
+
Continuously refactor code to keep it clean, maintainable and aligned with current requirements.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:20,000 --> 00:11:25,000
|
| 563 |
+
Remove any unused or unnecessary code to reduce complexity and technical debt.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:26,000 --> 00:11:31,000
|
| 567 |
+
Design solutions that are straightforward and meet immediate needs without overengineering.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:32,000 --> 00:11:36,000
|
| 571 |
+
Complexity should only be added when justified by concrete requirements.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:38,000 --> 00:11:40,000
|
| 575 |
+
Prioritize delivering value.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:40,000 --> 00:11:46,000
|
| 579 |
+
Prioritize tasks and features based on the value they provide to users or stakeholders.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:47,000 --> 00:11:52,000
|
| 583 |
+
Aim to deliver the highest value items first to maximize return on investment.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:53,000 --> 00:11:58,000
|
| 587 |
+
Postpone decisions about future features until they are absolutely necessary.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:59,000 --> 00:12:05,000
|
| 591 |
+
This avoids wasting time and effort on features that may never be needed, or that may change significantly
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:05,000 --> 00:12:06,000
|
| 595 |
+
before implementation.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:08,000 --> 00:12:10,000
|
| 599 |
+
Avoid premature optimization.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:10,000 --> 00:12:15,000
|
| 603 |
+
Focus on optimizing performance only when performance issues are observed and measured.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:16,000 --> 00:12:22,000
|
| 607 |
+
Avoid premature optimization, which can lead to overengineering and wasted effort on unnecessary improvements.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:23,000 --> 00:12:25,000
|
| 611 |
+
Use agile practices.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:26,000 --> 00:12:32,000
|
| 615 |
+
Adopt agile practices such as Scrum or Kanban to facilitate iterative development, frequent deliveries
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:32,000 --> 00:12:34,000
|
| 619 |
+
and continuous improvement.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:35,000 --> 00:12:41,000
|
| 623 |
+
Ensure collaboration and communication among cross-functional teams developers, testers, designers,
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:41,000 --> 00:12:46,000
|
| 627 |
+
product owners to promote a shared understanding of priorities and requirements.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:47,000 --> 00:12:54,000
|
| 631 |
+
validate assumptions based decisions on empirical data and user feedback, rather than assumptions or
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:54,000 --> 00:12:56,000
|
| 635 |
+
predictions about future needs.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:57,000 --> 00:13:02,000
|
| 639 |
+
Use prototypes and user testing to validate assumptions early in the development process.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:02,000 --> 00:13:07,000
|
| 643 |
+
This helps to avoid building unnecessary features or functionalities.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:08,000 --> 00:13:10,000
|
| 647 |
+
Let's review some case studies now.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:10,000 --> 00:13:16,000
|
| 651 |
+
Case studies illustrating the application and benefits of the you aren't gonna need it principle in
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:16,000 --> 00:13:22,000
|
| 655 |
+
software development can provide valuable insights into how this principle can be effectively implemented
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:22,000 --> 00:13:25,000
|
| 659 |
+
and its impact on project success.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:25,000 --> 00:13:31,000
|
| 663 |
+
Let's review different examples that illustrate different scenarios where Yanai principles are applied.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:32,000 --> 00:13:35,000
|
| 667 |
+
Start up app development scenario.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:35,000 --> 00:13:39,000
|
| 671 |
+
A startup is developing a new mobile app for task management.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:40,000 --> 00:13:43,000
|
| 675 |
+
How unique principle is applicable in this case?
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:44,000 --> 00:13:52,000
|
| 679 |
+
Initially, the team decides to implement basic task creation, editing and marking as complete functionalities.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:53,000 --> 00:13:59,000
|
| 683 |
+
They avoid adding advanced features like task dependencies or complex collaboration tools until user
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:59,000 --> 00:14:06,000
|
| 687 |
+
feedback indicates a clear demand for them, the team releases the app with minimal features to gather
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:06,000 --> 00:14:07,000
|
| 691 |
+
feedback quickly.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:07,000 --> 00:14:09,000
|
| 695 |
+
Based on user responses.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:09,000 --> 00:14:17,000
|
| 699 |
+
They prioritize subsequent features, such as reminders or sharing tasks that enhance usability and
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:17,000 --> 00:14:24,000
|
| 703 |
+
address real user needs by focusing on essential features and iterating based on user feedback.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:24,000 --> 00:14:29,000
|
| 707 |
+
The startup delivers a streamlined product that meets core user needs early on.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:29,000 --> 00:14:36,000
|
| 711 |
+
This approach accelerates time to market and ensures resources are invested in features that provide
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:36,000 --> 00:14:37,000
|
| 715 |
+
the most value.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:38,000 --> 00:14:44,000
|
| 719 |
+
E-commerce Platform Enhancement scenario an e-commerce platform is adding new payment options to improve
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:44,000 --> 00:14:46,000
|
| 723 |
+
user experience.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:47,000 --> 00:14:54,000
|
| 727 |
+
Let's understand how Jamie Principle may help us in this case, as the development team starts by integrating
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:54,000 --> 00:14:59,000
|
| 731 |
+
a popular payment gateway that covers the majority of user transactions.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:59,000 --> 00:15:06,000
|
| 735 |
+
They delay integrating less commonly used payment options until demand for them becomes evident through
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:06,000 --> 00:15:09,000
|
| 739 |
+
transaction data and user feedback.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:09,000 --> 00:15:15,000
|
| 743 |
+
Instead of building custom integrations for all potential payment gateways up front, the team designs
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:15,000 --> 00:15:22,000
|
| 747 |
+
a modular architecture that allows for easy scalability and addition of new payment options as needed.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:22,000 --> 00:15:28,000
|
| 751 |
+
By prioritizing the most used payment options initially and deferring less critical integrations, the
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:28,000 --> 00:15:33,000
|
| 755 |
+
platform enhances user experience without unnecessary complexity.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:33,000 --> 00:15:40,000
|
| 759 |
+
This approach also reduces initial development costs and ensures resources are allocated based on actual
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:40,000 --> 00:15:43,000
|
| 763 |
+
user behavior and preferences.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:44,000 --> 00:15:48,000
|
| 767 |
+
Social media platform development scenario.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:48,000 --> 00:15:51,000
|
| 771 |
+
Building a social media platform.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:51,000 --> 00:15:56,000
|
| 775 |
+
In this case, Yani principle also helps us to be more efficient.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:57,000 --> 00:16:03,000
|
| 779 |
+
Start with basic user registration, profile creation and posting functionalities.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:04,000 --> 00:16:10,000
|
| 783 |
+
Delay implementing advanced features like analytics, complex privacy settings, or extensive social
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:10,000 --> 00:16:15,000
|
| 787 |
+
network integration until user feedback indicates a clear demand for them.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:16,000 --> 00:16:23,000
|
| 791 |
+
Continuously iterate based on user feedback, adding new features or refining existing ones in response
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:23,000 --> 00:16:25,000
|
| 795 |
+
to real user needs and behaviors.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:26,000 --> 00:16:32,000
|
| 799 |
+
To help you understand this principle better, I prepared code examples before and after we applied
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:32,000 --> 00:16:35,000
|
| 803 |
+
our knowledge about yogini principle.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:16:35,000 --> 00:16:37,000
|
| 807 |
+
Let's review these examples together.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:16:38,000 --> 00:16:40,000
|
| 811 |
+
Just a reminder.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:16:40,000 --> 00:16:46,000
|
| 815 |
+
As always, you can find all source code examples attached to the lesson if you have any questions about
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:46,000 --> 00:16:52,000
|
| 819 |
+
the examples presented, please feel free to ask in the comments below the video and I'll be happy to
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:52,000 --> 00:16:53,000
|
| 823 |
+
respond.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:53,000 --> 00:16:58,000
|
| 827 |
+
Let's begin by reviewing the code before applying the you aren't gonna need it principle.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:59,000 --> 00:17:03,000
|
| 831 |
+
Imagine you are tasked with implementing a messaging application.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:03,000 --> 00:17:07,000
|
| 835 |
+
What key features come to mind as essential?
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:17:07,000 --> 00:17:13,000
|
| 839 |
+
The most critical functions for a messaging app are sending and receiving messages, right?
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:17:13,000 --> 00:17:20,000
|
| 843 |
+
However, for some reason, you also decided to implement features like archiving messages, deleting
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:17:20,000 --> 00:17:22,000
|
| 847 |
+
messages, and forwarding messages.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:17:23,000 --> 00:17:23,000
|
| 851 |
+
Why?
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:17:24,000 --> 00:17:29,000
|
| 855 |
+
Because you thought it might be a good idea to have these features in the messaging app.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:17:29,000 --> 00:17:36,000
|
| 859 |
+
The messaging app class includes additional functionalities such as archive message, delete message
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:36,000 --> 00:17:42,000
|
| 863 |
+
and forward message, which are not immediately necessary for basic messaging operations.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:17:42,000 --> 00:17:48,000
|
| 867 |
+
These methods anticipate future requirements, but add unnecessary complexity and increase the size
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:17:48,000 --> 00:17:50,000
|
| 871 |
+
of the code base up front.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:50,000 --> 00:17:52,000
|
| 875 |
+
But remember what we've learned.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:52,000 --> 00:17:55,000
|
| 879 |
+
Focus on essential features.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:55,000 --> 00:17:59,000
|
| 883 |
+
Use agile practices and introduce improvements iteratively.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:18:00,000 --> 00:18:06,000
|
| 887 |
+
Focus on delivering value, perhaps creating channels with paid content and enabling content.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:18:06,000 --> 00:18:13,000
|
| 891 |
+
Authors to monetize their content in public channels would bring more value to your messaging app than
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:13,000 --> 00:18:16,000
|
| 895 |
+
implementing archiving and forwarding features.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:17,000 --> 00:18:20,000
|
| 899 |
+
You see, what may seem obvious is never guaranteed.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:18:20,000 --> 00:18:24,000
|
| 903 |
+
Each team member needs to perform their role at the highest level.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:18:25,000 --> 00:18:31,000
|
| 907 |
+
Managers, product teams, and marketing teams should set priorities, highlight values, and make data
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:18:31,000 --> 00:18:32,000
|
| 911 |
+
driven decisions.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:18:33,000 --> 00:18:36,000
|
| 915 |
+
The yagna principle should help us do just that.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:18:37,000 --> 00:18:40,000
|
| 919 |
+
Now let's take a look at the solution file.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:18:41,000 --> 00:18:47,000
|
| 923 |
+
If the task was to create a messaging app that sends and receives messages during this iteration, then
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:18:47,000 --> 00:18:54,000
|
| 927 |
+
delivering that functionality on the expected level of quality is precisely what you need.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:18:54,000 --> 00:18:58,000
|
| 931 |
+
As you can see, the messaging app in this case has two methods.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:18:58,000 --> 00:19:01,000
|
| 935 |
+
Send message and receive message.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:19:01,000 --> 00:19:01,000
|
| 939 |
+
That's it.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:19:02,000 --> 00:19:08,000
|
| 943 |
+
By removing unnecessary methods, the code becomes simpler, more focused, and easier to maintain.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:19:09,000 --> 00:19:16,000
|
| 947 |
+
Solution has a streamlined design with fewer methods, making the code base cleaner and easier to understand.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:19:16,000 --> 00:19:22,000
|
| 951 |
+
With fewer features and complexities, there are fewer potential points of failure, reducing the likelihood
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:19:22,000 --> 00:19:23,000
|
| 955 |
+
of bugs and issues.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:19:24,000 --> 00:19:30,000
|
| 959 |
+
The simplified design allows for easier future enhancements based on actual user needs and feedback,
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:19:30,000 --> 00:19:35,000
|
| 963 |
+
without the burden of maintaining unused or unnecessary features.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:19:35,000 --> 00:19:42,000
|
| 967 |
+
This approach aligns with what is expected at this stage, using our team's efforts in the most efficient
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:19:42,000 --> 00:19:46,000
|
| 971 |
+
way and focusing on what brings the most value.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:19:46,000 --> 00:19:52,000
|
| 975 |
+
Of course, this isn't a ready for production application, but I want you to grasp the key principle
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:19:52,000 --> 00:19:53,000
|
| 979 |
+
here.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:19:53,000 --> 00:20:00,000
|
| 983 |
+
If you have any questions, please pose them below the video and I'll be happy to answer them in my
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:20:00,000 --> 00:20:01,000
|
| 987 |
+
course.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:20:01,000 --> 00:20:03,000
|
| 991 |
+
We already learned keys principle.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:20:03,000 --> 00:20:10,000
|
| 995 |
+
Very often my students ask me, so what is actually the difference between keys and principles?
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:20:10,000 --> 00:20:15,000
|
| 999 |
+
Because it looks like that Yagnya principle also simplifies everything.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:20:15,000 --> 00:20:18,000
|
| 1003 |
+
Then how it is different from keys principle.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:20:19,000 --> 00:20:20,000
|
| 1007 |
+
Let me explain the difference.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:20:21,000 --> 00:20:23,000
|
| 1011 |
+
As you aren't gonna need it principle.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:20:23,000 --> 00:20:30,000
|
| 1015 |
+
And to keep it simple, stupid principle are both guidelines in software development aimed at improving
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:20:30,000 --> 00:20:36,000
|
| 1019 |
+
code quality, maintainability and efficiency, but they emphasize different aspects of the development
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:20:36,000 --> 00:20:37,000
|
| 1023 |
+
process.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:20:37,000 --> 00:20:43,000
|
| 1027 |
+
Let's review the key characteristics of each principle and then we will analyze key differences between
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:20:43,000 --> 00:20:43,000
|
| 1031 |
+
them.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:20:44,000 --> 00:20:46,000
|
| 1035 |
+
You aren't going to need it.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:46,000 --> 00:20:53,000
|
| 1039 |
+
Principal Janey advises developers to implement only features that are necessary for the current iteration
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:53,000 --> 00:20:55,000
|
| 1043 |
+
or immediate requirements.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:55,000 --> 00:21:03,000
|
| 1047 |
+
It discourages adding functionalities based on anticipated future needs or hypothetical scenarios.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:21:03,000 --> 00:21:11,000
|
| 1051 |
+
Janey helps in avoiding premature optimization and overengineering of solutions by deferring decisions
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:21:11,000 --> 00:21:14,000
|
| 1055 |
+
about future features until they are actually needed.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:21:14,000 --> 00:21:20,000
|
| 1059 |
+
Developers reduce the risk of investing time and resources in unnecessary complexities.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:21:20,000 --> 00:21:27,000
|
| 1063 |
+
It promotes an iterative approach where software evolves based on real user feedback and changing requirements.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:21:28,000 --> 00:21:34,000
|
| 1067 |
+
Features are added incrementally as they are validated by user needs, ensuring that the software remains
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:21:34,000 --> 00:21:36,000
|
| 1071 |
+
lean and responsive.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:21:37,000 --> 00:21:39,000
|
| 1075 |
+
On the contrary, keep it simple.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:21:39,000 --> 00:21:42,000
|
| 1079 |
+
Stupid principle has the following key characteristics.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:21:43,000 --> 00:21:47,000
|
| 1083 |
+
Kiss emphasizes keeping code and design as simple as possible.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:21:47,000 --> 00:21:54,000
|
| 1087 |
+
It encourages developers to choose straightforward solutions over complex ones, prioritizing clarity
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:21:54,000 --> 00:21:56,000
|
| 1091 |
+
and ease of understanding.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:21:56,000 --> 00:22:04,000
|
| 1095 |
+
It advocates for minimalistic designs and implementations that are easy to maintain, debug, and extend.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:22:05,000 --> 00:22:12,000
|
| 1099 |
+
By reducing complexity, Kiss aims to improve code readability and reduce the likelihood of errors.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:22:12,000 --> 00:22:19,000
|
| 1103 |
+
Kiss often focuses on the end user experience, aiming to create intuitive interfaces and functionalities
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:22:19,000 --> 00:22:24,000
|
| 1107 |
+
that are easy for users to understand and use without unnecessary complexity.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:22:25,000 --> 00:22:29,000
|
| 1111 |
+
So let's sum it up and highlight key differences.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:22:30,000 --> 00:22:38,000
|
| 1115 |
+
JNI primarily addresses the scope of features and functionalities, guiding decisions on what to implement
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:22:38,000 --> 00:22:39,000
|
| 1119 |
+
based on immediate needs.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:22:40,000 --> 00:22:47,000
|
| 1123 |
+
In contrast, keys focuses on the simplicity of design and implementation, advocating for straightforward
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:22:47,000 --> 00:22:50,000
|
| 1127 |
+
solutions regardless of the feature set.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:22:51,000 --> 00:22:58,000
|
| 1131 |
+
Janney suggests delaying decisions about future features until they are necessary, whereas Keyes is
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:22:58,000 --> 00:23:05,000
|
| 1135 |
+
concerned with making design and implementation decisions that prioritize simplicity from the outset.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:23:06,000 --> 00:23:13,000
|
| 1139 |
+
Janney helps mitigate the risk of investing resources in features that may not be used or may change
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:23:13,000 --> 00:23:14,000
|
| 1143 |
+
significantly.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:23:15,000 --> 00:23:21,000
|
| 1147 |
+
Kis mitigates the risk of complexity and maintenance overhead by promoting simpler, more manageable
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:23:21,000 --> 00:23:22,000
|
| 1151 |
+
designs.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:23:23,000 --> 00:23:30,000
|
| 1155 |
+
In essence, while both Yanai and Kis promote simplicity and efficiency in software development, Yanai
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:23:30,000 --> 00:23:37,000
|
| 1159 |
+
specifically addresses feature scope and anticipatory design decisions, whereas quis focuses on simplicity
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:23:37,000 --> 00:23:42,000
|
| 1163 |
+
and design and implementation as guiding principles throughout the development process.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:23:42,000 --> 00:23:49,000
|
| 1167 |
+
Integrating both principles can lead to software that is both minimalistic and responsive to real user
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:23:49,000 --> 00:23:49,000
|
| 1171 |
+
needs.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:23:50,000 --> 00:23:53,000
|
| 1175 |
+
That's all what I wanted to discuss with you today.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:23:53,000 --> 00:23:56,000
|
| 1179 |
+
Let's recap what we've learned in the lesson.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:23:57,000 --> 00:24:02,000
|
| 1183 |
+
We defined the unit principle and discussed its core concepts.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:24:02,000 --> 00:24:07,000
|
| 1187 |
+
We explored the benefits of using the unit principle in software development.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:24:08,000 --> 00:24:12,000
|
| 1191 |
+
You learned how to apply the unit principle effectively in your projects.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:24:13,000 --> 00:24:20,000
|
| 1195 |
+
We reviewed several case studies demonstrating the successful application of the Yanai principle.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:24:21,000 --> 00:24:26,000
|
| 1199 |
+
You analyzed code examples to understand the practical implementation of Yanai.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:24:26,000 --> 00:24:32,000
|
| 1203 |
+
We compared the Yanai principle with the keys principle, highlighting the key differences.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:24:33,000 --> 00:24:35,000
|
| 1207 |
+
That's all for this lesson.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:24:36,000 --> 00:24:38,000
|
| 1211 |
+
Thanks a lot for your attention.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:24:38,000 --> 00:24:41,000
|
| 1215 |
+
Have a great day and see you in the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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:11,000
|
| 7 |
+
Today we have one more important lesson dedicated to the dry principle.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:11,000 --> 00:00:15,000
|
| 11 |
+
Let me elaborate on what we are going to learn in this lesson.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:15,000 --> 00:00:17,000
|
| 15 |
+
So here's what we'll be covering today.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:17,000 --> 00:00:22,000
|
| 19 |
+
We'll start with the basics by defining the don't repeat yourself principle.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:22,000 --> 00:00:28,000
|
| 23 |
+
I'll explain what it means and why it's a fundamental concept in software development.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:28,000 --> 00:00:33,000
|
| 27 |
+
Next, we'll delve into the benefits of using the Dry principle.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:33,000 --> 00:00:39,000
|
| 31 |
+
You'll understand how it can improve code maintainability, reduce errors, and enhance overall efficiency
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:39,000 --> 00:00:40,000
|
| 35 |
+
in your projects.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:41,000 --> 00:00:45,000
|
| 39 |
+
After that, I'll show you how to apply the Dry principle in practice.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:46,000 --> 00:00:52,000
|
| 43 |
+
We'll look at various techniques and strategies to ensure your code adheres to this principle, making
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:52,000 --> 00:00:53,000
|
| 47 |
+
it more robust and scalable.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:54,000 --> 00:00:57,000
|
| 51 |
+
We'll also discuss some contrasting concepts.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:57,000 --> 00:01:02,000
|
| 55 |
+
Specifically, write everything twice and avoid hasty abstractions.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:02,000 --> 00:01:02,000
|
| 59 |
+
Principles.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:03,000 --> 00:01:09,000
|
| 63 |
+
These concepts will provide a broader perspective on when and how to apply dry effectively.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:10,000 --> 00:01:13,000
|
| 67 |
+
Then we'll explore case studies of the Dry principle.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:13,000 --> 00:01:19,000
|
| 71 |
+
I'll present real world examples where Dry has been successfully implemented, highlighting the positive
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:19,000 --> 00:01:22,000
|
| 75 |
+
impacts it has had on different projects.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:23,000 --> 00:01:27,000
|
| 79 |
+
Finally, we will go through code examples to see the dry principle in action.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:27,000 --> 00:01:34,000
|
| 83 |
+
You will get to see before and after scenarios of code refactoring to understand the practical benefits
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:34,000 --> 00:01:36,000
|
| 87 |
+
of eliminating redundancy.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:36,000 --> 00:01:39,000
|
| 91 |
+
So let's dive in and start our lesson.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:40,000 --> 00:01:43,000
|
| 95 |
+
Let's learn first the definition of the dry principle.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:44,000 --> 00:01:50,000
|
| 99 |
+
The dry principle, which stands for don't repeat yourself, is a fundamental concept in software engineering
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:50,000 --> 00:01:53,000
|
| 103 |
+
aimed at reducing repetition within code.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:54,000 --> 00:02:00,000
|
| 107 |
+
The principle advocates for the minimization of redundancy by ensuring that every piece of knowledge
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:00,000 --> 00:02:05,000
|
| 111 |
+
or logic is represented in a single, unambiguous place in the code base.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:06,000 --> 00:02:11,000
|
| 115 |
+
This approach leads to cleaner, more maintainable and less error prone code.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:11,000 --> 00:02:18,000
|
| 119 |
+
By following the Dry principle, developers can avoid the pitfalls of duplicating code such as increased
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:18,000 --> 00:02:24,000
|
| 123 |
+
risk of bugs, difficulties in making updates, and inconsistency across the application.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:24,000 --> 00:02:32,000
|
| 127 |
+
Implementing the Dry principle often involves abstracting common functionality into functions, modules,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:32,000 --> 00:02:35,000
|
| 131 |
+
or classes that can be reused throughout the code base.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:36,000 --> 00:02:43,000
|
| 135 |
+
The Don't Repeat Yourself principle was introduced by Andy Hunt and Dave Thomas in their influential
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:43,000 --> 00:02:47,000
|
| 139 |
+
book The Pragmatic Programmer, published in 1999.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:48,000 --> 00:02:53,000
|
| 143 |
+
This book has had a significant impact on modern software development.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:53,000 --> 00:03:00,000
|
| 147 |
+
practices, advocating for practical and efficient coding techniques that enhance productivity and code
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:00,000 --> 00:03:00,000
|
| 151 |
+
quality.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:01,000 --> 00:03:06,000
|
| 155 |
+
As always, I need to motivate you to use this principle.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:06,000 --> 00:03:12,000
|
| 159 |
+
You will be motivated to learn and apply this principle only when you understand the benefits of using
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:12,000 --> 00:03:12,000
|
| 163 |
+
it.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:13,000 --> 00:03:19,000
|
| 167 |
+
So let me explain why you need to use the Dry principle and what benefits you can get from using it
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:20,000 --> 00:03:25,000
|
| 171 |
+
as a don't repeat yourself principle is a cornerstone of efficient software development.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:26,000 --> 00:03:32,000
|
| 175 |
+
Its application offers several key benefits that enhance the overall quality and maintainability of
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:32,000 --> 00:03:32,000
|
| 179 |
+
code.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:33,000 --> 00:03:35,000
|
| 183 |
+
Let's review benefits one by one.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:35,000 --> 00:03:37,000
|
| 187 |
+
Improved code maintainability.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:38,000 --> 00:03:44,000
|
| 191 |
+
When code is duplicated, any change needs to be made in multiple places, increasing the likelihood
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:44,000 --> 00:03:45,000
|
| 195 |
+
of errors.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:45,000 --> 00:03:49,000
|
| 199 |
+
By ensuring that each piece of logic is defined in one place.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:49,000 --> 00:03:55,000
|
| 203 |
+
The Dry principle makes updating and maintaining code easier and less error prone.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:56,000 --> 00:03:58,000
|
| 207 |
+
Reduced risk of bugs.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:58,000 --> 00:04:05,000
|
| 211 |
+
Redundant code increases the chances of inconsistencies and bugs when the same logic is repeated in
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:05,000 --> 00:04:06,000
|
| 215 |
+
multiple places.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:06,000 --> 00:04:10,000
|
| 219 |
+
A bug fixed in one instance might still exist in another.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:11,000 --> 00:04:17,000
|
| 223 |
+
The Dry principle helps ensure that a bug only needs to be fixed in one location.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:18,000 --> 00:04:20,000
|
| 227 |
+
Enhanced readability and clarity.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:21,000 --> 00:04:26,000
|
| 231 |
+
Code that adheres to the Dry principle tends to be more concise and easier to read.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:26,000 --> 00:04:33,000
|
| 235 |
+
When developers do not have to sift through redundant code, they can more quickly understand the functionality
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:33,000 --> 00:04:35,000
|
| 239 |
+
and purpose of the code base.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:36,000 --> 00:04:37,000
|
| 243 |
+
Easier refactoring.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:38,000 --> 00:04:41,000
|
| 247 |
+
Refactoring is simpler when code is not repeated.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:42,000 --> 00:04:48,000
|
| 251 |
+
If a certain logic needs to be changed or optimized, it can be done in one place without worrying about
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:48,000 --> 00:04:50,000
|
| 255 |
+
missing other instances of the same logic.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:51,000 --> 00:04:59,000
|
| 259 |
+
Increased efficiency By abstracting common functionalities into reusable components such as functions,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:59,000 --> 00:05:00,000
|
| 263 |
+
modules, or classes.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:00,000 --> 00:05:03,000
|
| 267 |
+
Developers can write less code.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:03,000 --> 00:05:09,000
|
| 271 |
+
This not only speeds up the development process, but also ensures a more consistent implementation
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:09,000 --> 00:05:11,000
|
| 275 |
+
of common tasks.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:12,000 --> 00:05:14,000
|
| 279 |
+
Better code reusability.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:14,000 --> 00:05:19,000
|
| 283 |
+
The Dry principle encourages the creation of modular reusable components.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:20,000 --> 00:05:25,000
|
| 287 |
+
This modularity allows developers to leverage existing code across different parts of the application,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:25,000 --> 00:05:30,000
|
| 291 |
+
or even in different projects, promoting a more efficient development process.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:31,000 --> 00:05:34,000
|
| 295 |
+
Consistency across the code base.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:34,000 --> 00:05:41,000
|
| 299 |
+
When logic is defined in one place and reused, it ensures consistent behavior across the application.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:42,000 --> 00:05:48,000
|
| 303 |
+
This consistency is crucial for maintaining a reliable and predictable code base, especially in large
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:48,000 --> 00:05:50,000
|
| 307 |
+
and complex systems.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:51,000 --> 00:05:56,000
|
| 311 |
+
Facilitates collaboration in a team environment following the Dry principle.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:56,000 --> 00:05:59,000
|
| 315 |
+
Helps ensure that everyone is on the same page.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:59,000 --> 00:06:06,000
|
| 319 |
+
Clear Non-redundant code makes it easier for team members to understand and work on the code base,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:06,000 --> 00:06:10,000
|
| 323 |
+
improving collaboration and reducing the learning curve for new developers.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:11,000 --> 00:06:18,000
|
| 327 |
+
By adhering to the DRI principle, developers can create more robust, efficient and maintainable software.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:19,000 --> 00:06:25,000
|
| 331 |
+
This principle not only saves time and effort, but also contributes to the creation of high quality
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:25,000 --> 00:06:30,000
|
| 335 |
+
code that can easily adapt to changes and new requirements.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:30,000 --> 00:06:36,000
|
| 339 |
+
In the case you will have any questions related to the slides or to my comments, feel free to post
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:36,000 --> 00:06:39,000
|
| 343 |
+
your questions below the video and I will be happy to answer.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:40,000 --> 00:06:41,000
|
| 347 |
+
Let's continue.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:42,000 --> 00:06:46,000
|
| 351 |
+
And how can you start applying the Dry principle to your projects?
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:47,000 --> 00:06:48,000
|
| 355 |
+
What is the algorithm?
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:49,000 --> 00:06:51,000
|
| 359 |
+
Algorithm is simple and straightforward.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:51,000 --> 00:06:52,000
|
| 363 |
+
Let me share it with you.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:53,000 --> 00:06:59,000
|
| 367 |
+
Applying the don't repeat yourself principle involves several key practices and strategies to reduce
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:59,000 --> 00:07:02,000
|
| 371 |
+
code duplication and enhance maintainability.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:02,000 --> 00:07:07,000
|
| 375 |
+
Here are some steps and techniques to help you apply the DRI principle effectively.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:08,000 --> 00:07:10,000
|
| 379 |
+
Identify redundant code.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:11,000 --> 00:07:15,000
|
| 383 |
+
Regularly review your code base to identify duplicated code.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:15,000 --> 00:07:20,000
|
| 387 |
+
Look for similar or identical blocks of code that performs the same function.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:21,000 --> 00:07:26,000
|
| 391 |
+
Use tools that can automatically detect duplicated code within your code base.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:27,000 --> 00:07:28,000
|
| 395 |
+
Abstract.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:28,000 --> 00:07:29,000
|
| 399 |
+
Repeated logic.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:29,000 --> 00:07:36,000
|
| 403 |
+
Encapsulate repeated code in functions or methods that can be called from different parts of your application.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:37,000 --> 00:07:43,000
|
| 407 |
+
Use object oriented programming principles to create classes and objects that encapsulate common behaviors
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:43,000 --> 00:07:44,000
|
| 411 |
+
and properties.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:45,000 --> 00:07:47,000
|
| 415 |
+
Modularize code.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:48,000 --> 00:07:53,000
|
| 419 |
+
Organize your code into modules or packages that contain reusable components.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:53,000 --> 00:07:57,000
|
| 423 |
+
This makes it easier to reuse and maintain code.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:58,000 --> 00:08:03,000
|
| 427 |
+
Extract common functionalities into libraries that can be shared across multiple projects.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:04,000 --> 00:08:06,000
|
| 431 |
+
Use design patterns.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:07,000 --> 00:08:14,000
|
| 435 |
+
Singleton ensures that a class has only one instance and provide a global point of access to it.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:14,000 --> 00:08:21,000
|
| 439 |
+
Factory pattern create objects without specifying the exact class of object that will be created.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:22,000 --> 00:08:27,000
|
| 443 |
+
Decorator add behavior to objects dynamically without modifying their code.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:29,000 --> 00:08:31,000
|
| 447 |
+
Leverage inheritance and polymorphism.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:32,000 --> 00:08:38,000
|
| 451 |
+
Use inheritance to create a base class with common functionality and extend it in subclasses.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:39,000 --> 00:08:46,000
|
| 455 |
+
Implement polymorphism to allow different classes to be treated as instances of the same class through
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:46,000 --> 00:08:47,000
|
| 459 |
+
a common interface.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:48,000 --> 00:08:50,000
|
| 463 |
+
Utilize template methods.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:51,000 --> 00:08:58,000
|
| 467 |
+
Template method defines a skeleton of an algorithm in a base class, and allows subclasses to override
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:58,000 --> 00:09:01,000
|
| 471 |
+
specific steps without changing the algorithm structure.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:02,000 --> 00:09:05,000
|
| 475 |
+
Use frameworks and libraries.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:05,000 --> 00:09:11,000
|
| 479 |
+
Leverage frameworks that provide built in functionalities to avoid writing boilerplate code.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:11,000 --> 00:09:16,000
|
| 483 |
+
Utilize third party libraries for common tasks instead of reinventing the wheel.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:18,000 --> 00:09:19,000
|
| 487 |
+
refactor regularly.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:20,000 --> 00:09:26,000
|
| 491 |
+
Make refactoring a regular part of your development process to keep your code base clean and dry.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:27,000 --> 00:09:28,000
|
| 495 |
+
Test driven development.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:29,000 --> 00:09:34,000
|
| 499 |
+
Write tests before coding to ensure that refactoring does not introduce bugs.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:35,000 --> 00:09:37,000
|
| 503 |
+
Maintain clear documentation.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:38,000 --> 00:09:44,000
|
| 507 |
+
Write clear and concise comments explaining the purpose and usage of abstracted functions, methods,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:44,000 --> 00:09:46,000
|
| 511 |
+
and classes.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:47,000 --> 00:09:53,000
|
| 515 |
+
Maintain comprehensive documentation for your code base, modules and libraries to aid in understanding
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:53,000 --> 00:09:54,000
|
| 519 |
+
and reusability.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:56,000 --> 00:10:01,000
|
| 523 |
+
But if you think that Dry is a rule of thumb everywhere and for everyone, you are wrong.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:02,000 --> 00:10:09,000
|
| 527 |
+
There are principles that contradicts dry principle and you need to be aware about them in order to
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:09,000 --> 00:10:12,000
|
| 531 |
+
be able to apply dry principle wisely.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:13,000 --> 00:10:16,000
|
| 535 |
+
Let's review such concepts as wet and aha.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:17,000 --> 00:10:19,000
|
| 539 |
+
Let's start with wet.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:19,000 --> 00:10:23,000
|
| 543 |
+
That stands for Write everything twice or we enjoy typing.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:24,000 --> 00:10:29,000
|
| 547 |
+
Wet is a tongue in cheek acronym that represents the opposite of don't repeat yourself.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:30,000 --> 00:10:36,000
|
| 551 |
+
It humorously suggests writing duplicate or similar code in multiple places rather than consolidating
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:36,000 --> 00:10:37,000
|
| 555 |
+
it.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:37,000 --> 00:10:44,000
|
| 559 |
+
Although the term is used humorously, it highlights a practice that should be avoided in software development.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:45,000 --> 00:10:51,000
|
| 563 |
+
Writing duplicate code increases the chances of inconsistencies, introduces maintenance overhead,
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:51,000 --> 00:10:55,000
|
| 567 |
+
and makes the code base harder to refactor and extend.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:56,000 --> 00:11:01,000
|
| 571 |
+
Wet code tends to be less maintainable and more error prone over time.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:02,000 --> 00:11:08,000
|
| 575 |
+
It violates principles of code reuse, increases development effort, and can lead to inefficiencies
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:08,000 --> 00:11:11,000
|
| 579 |
+
in debugging and updating the software.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:13,000 --> 00:11:18,000
|
| 583 |
+
Let's now review our Hop principles that stands for Avoid Hasty Abstractions.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:18,000 --> 00:11:18,000
|
| 587 |
+
abstractions.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:19,000 --> 00:11:25,000
|
| 591 |
+
Aha advises against prematurely abstracting code or creating overly complex abstractions before fully
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:25,000 --> 00:11:29,000
|
| 595 |
+
understanding the problem, domain or requirements.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:30,000 --> 00:11:37,000
|
| 599 |
+
This principle cautions developers against introducing unnecessary complexity or creating overly abstract
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:37,000 --> 00:11:40,000
|
| 603 |
+
solutions without clear justification.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:40,000 --> 00:11:45,000
|
| 607 |
+
It advocates for simplicity and clarity in code design and architecture.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:46,000 --> 00:11:53,000
|
| 611 |
+
Rushing into abstractions can lead to unnecessary overhead, reduced code readability, and increased
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:53,000 --> 00:11:55,000
|
| 615 |
+
cognitive load for developers.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:55,000 --> 00:12:02,000
|
| 619 |
+
It may also result in solutions that are overly generic or difficult to maintain, especially if the
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:02,000 --> 00:12:08,000
|
| 623 |
+
abstractions don't accurately reflect the problem domain or evolve with changing requirements.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:10,000 --> 00:12:15,000
|
| 627 |
+
And now let's summarize how wet and aha relate to dry principle.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:16,000 --> 00:12:22,000
|
| 631 |
+
While Dry emphasizes eliminating redundancy and promoting code reuse to enhance maintainability and
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:22,000 --> 00:12:23,000
|
| 635 |
+
consistency.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:23,000 --> 00:12:30,000
|
| 639 |
+
Wet and Aha caution against practices that can lead to complexity, inefficiency, and increased development
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:30,000 --> 00:12:31,000
|
| 643 |
+
effort.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:32,000 --> 00:12:36,000
|
| 647 |
+
Finding a balance between these principles is crucial in software development.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:36,000 --> 00:12:45,000
|
| 651 |
+
DRI encourages efficient, reusable code, while awareness of Wet and Aha helps developers avoid pitfalls
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:45,000 --> 00:12:49,000
|
| 655 |
+
such as premature optimization or excessive abstraction.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:50,000 --> 00:12:56,000
|
| 659 |
+
To better understand the application and benefits of the don't repeat yourself principle, let's explore
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:56,000 --> 00:13:00,000
|
| 663 |
+
some real world case studies where this principle was successfully implemented.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:01,000 --> 00:13:02,000
|
| 667 |
+
Case study one.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:03,000 --> 00:13:05,000
|
| 671 |
+
Refactoring a legacy code base scenario.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:06,000 --> 00:13:12,000
|
| 675 |
+
A software development team inherited a legacy code base for a financial application.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:12,000 --> 00:13:18,000
|
| 679 |
+
The code base had grown organically over the years, resulting in significant code duplication.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:19,000 --> 00:13:24,000
|
| 683 |
+
Different modules implemented similar functionalities with slight variations leading to maintenance
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:24,000 --> 00:13:27,000
|
| 687 |
+
challenges and frequent bugs.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:28,000 --> 00:13:33,000
|
| 691 |
+
The team conducted a thorough code review to identify redundant code sections.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:34,000 --> 00:13:40,000
|
| 695 |
+
Common functionalities such as data validation and calculation methods were abstracted into reusable
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:40,000 --> 00:13:41,000
|
| 699 |
+
functions and classes.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:42,000 --> 00:13:48,000
|
| 703 |
+
The code base was reorganized into modules, each responsible for a specific functionality.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:49,000 --> 00:13:51,000
|
| 707 |
+
For example, user authentication.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:51,000 --> 00:13:53,000
|
| 711 |
+
Transaction processing.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:53,000 --> 00:13:59,000
|
| 715 |
+
As a result, the overall code base size was reduced by 30%.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:00,000 --> 00:14:07,000
|
| 719 |
+
Changes in business logic required modifications in a single location, reducing the risk of inconsistencies.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:08,000 --> 00:14:14,000
|
| 723 |
+
New developers found it easier to understand the code base due to clear modular structures, but you
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:14,000 --> 00:14:17,000
|
| 727 |
+
need to be extra careful in cases like this.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:17,000 --> 00:14:24,000
|
| 731 |
+
And there is a golden rule that before start doing any refactoring, make sure you have a robust test
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:24,000 --> 00:14:26,000
|
| 735 |
+
coverage on different testing layers.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:27,000 --> 00:14:33,000
|
| 739 |
+
If you don't have those, you need to start from test coverage of your application and only after that
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:33,000 --> 00:14:35,000
|
| 743 |
+
proceed with refactoring.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:37,000 --> 00:14:41,000
|
| 747 |
+
Case study two developing a multi-platform mobile application scenario.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:42,000 --> 00:14:48,000
|
| 751 |
+
A startup company was developing a mobile application for both iOS and Android platforms.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:48,000 --> 00:14:54,000
|
| 755 |
+
Initially, separate code bases were maintained for each platform, leading to duplicate logic for code
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:54,000 --> 00:14:59,000
|
| 759 |
+
functionalities like data synchronization and user notifications.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:59,000 --> 00:15:07,000
|
| 763 |
+
The team decided to use a cross platform framework, React Native, to write shared code for both platforms.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:08,000 --> 00:15:15,000
|
| 767 |
+
Reusable components were created for UI elements and business logic, ensuring that common functionalities
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:15,000 --> 00:15:18,000
|
| 771 |
+
were implemented once and reused across the app.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:19,000 --> 00:15:26,000
|
| 775 |
+
Core business logic was centralized in shared modules, while platform specific code was minimized.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:27,000 --> 00:15:33,000
|
| 779 |
+
As a result, a single code base for both platforms reduced development and maintenance efforts.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:34,000 --> 00:15:40,000
|
| 783 |
+
The use of shared components ensured a consistent user experience across iOS and Android.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:41,000 --> 00:15:47,000
|
| 787 |
+
Time to market was significantly reduced due to the elimination of redundant coding efforts.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:48,000 --> 00:15:53,000
|
| 791 |
+
Case study three optimizing an E-commerce website.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:54,000 --> 00:16:00,000
|
| 795 |
+
An e-commerce company was facing performance issues and high maintenance costs due to duplicated code
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:00,000 --> 00:16:07,000
|
| 799 |
+
across various parts of their website, including product listing, search functionality, and checkout
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:07,000 --> 00:16:08,000
|
| 803 |
+
process.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:16:09,000 --> 00:16:15,000
|
| 807 |
+
The team implemented a template system for rendering web pages, allowing common page elements, for
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:16:15,000 --> 00:16:21,000
|
| 811 |
+
example headers, footers, product cards to be defined once and reused.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:16:22,000 --> 00:16:29,000
|
| 815 |
+
A unified API layer was introduced to handle data retrieval and processing, replacing multiple redundant
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:29,000 --> 00:16:30,000
|
| 819 |
+
data access methods.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:31,000 --> 00:16:38,000
|
| 823 |
+
The application was refactored into a service oriented architecture where independent services handled
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:38,000 --> 00:16:39,000
|
| 827 |
+
specific business functions.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:40,000 --> 00:16:46,000
|
| 831 |
+
As a result, reduced duplication led to a leaner code base, improving site performance.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:16:47,000 --> 00:16:54,000
|
| 835 |
+
New features and updates were implemented faster as changes in one service did not require modifications
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:54,000 --> 00:17:02,000
|
| 839 |
+
across multiple parts of the code base, the Dry principle led to lower long term maintenance costs
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:17:02,000 --> 00:17:05,000
|
| 843 |
+
by reducing code redundancy and complexity.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:17:06,000 --> 00:17:09,000
|
| 847 |
+
Case study for streamlining a CRM system.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:17:10,000 --> 00:17:17,000
|
| 851 |
+
A large enterprise used a customer relationship management system with extensive code duplication in
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:17:17,000 --> 00:17:19,000
|
| 855 |
+
its modules for managing customer data.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:17:19,000 --> 00:17:21,000
|
| 859 |
+
sales tracking and reporting.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:22,000 --> 00:17:29,000
|
| 863 |
+
Data handling routines were centralized into a common library, ensuring consistent data validation
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:17:29,000 --> 00:17:30,000
|
| 867 |
+
and processing.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:17:31,000 --> 00:17:38,000
|
| 871 |
+
Common UI elements, such as forms and tables were refactored into reusable widgets.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:39,000 --> 00:17:45,000
|
| 875 |
+
Automated tests were written for the centralized components to ensure reliability and facilitate future
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:45,000 --> 00:17:46,000
|
| 879 |
+
changes.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:47,000 --> 00:17:54,000
|
| 883 |
+
As a result, centralized data handling ensured consistent business rules across all modules.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:17:55,000 --> 00:18:00,000
|
| 887 |
+
Automated tests for common components reduce the likelihood of bugs and regressions.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:18:01,000 --> 00:18:08,000
|
| 891 |
+
Developers could focus on new features rather than duplicating existing logic, leading to more efficient
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:08,000 --> 00:18:10,000
|
| 895 |
+
development cycles.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:10,000 --> 00:18:16,000
|
| 899 |
+
These case studies illustrate how the drive principle can be effectively applied in various contexts
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:18:16,000 --> 00:18:24,000
|
| 903 |
+
to improve code maintainability, reduce bugs, and streamline development processes by minimising redundancy.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:18:24,000 --> 00:18:28,000
|
| 907 |
+
Teams can create more robust and scalable software systems.
|
| 908 |
+
|
38 - Object-oriented Architecture, Clean Code Design (Advanced)/007 Source-code-examples-shown-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/dry
|
38 - Object-oriented Architecture, Clean Code Design (Advanced)/008 Packaging Pricniples p.1 Cohesion Principles_en.srt
ADDED
|
@@ -0,0 +1,1112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello, France and this nation will learn different approaches to group here called into multiple packages
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:13,000
|
| 7 |
+
to keep the architecture clean.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:18,000
|
| 11 |
+
In this lesson, we will cover core principles regarding module structuring and code organization.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:22,000
|
| 15 |
+
These principles will help you to keep your architecture clean.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:28,000
|
| 19 |
+
Also, following these principles, you make your code easier to scale, maintain and reuse.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:29,000 --> 00:00:32,000
|
| 23 |
+
I'll explain why do we need a good structure and how to create it?
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:33,000 --> 00:00:37,000
|
| 27 |
+
We will talk about factors that is worse to consider when we talk about packaging.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:38,000 --> 00:00:39,000
|
| 31 |
+
This topic takes time.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:39,000 --> 00:00:42,000
|
| 35 |
+
That probably is more than for one lesson.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:42,000 --> 00:00:47,000
|
| 39 |
+
That's why we'll start learning group and principles in this lesson and we'll proceed further in the
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:47,000 --> 00:00:48,000
|
| 43 |
+
course.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:48,000 --> 00:00:51,000
|
| 47 |
+
In the lesson, we'll talk about cohesion principles.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:52,000 --> 00:00:57,000
|
| 51 |
+
Namely, we'll discuss common closure, common use and we release equivalence principles.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:58,000 --> 00:01:03,000
|
| 55 |
+
Let's start, as I already said in the lesson, we'll discuss group of different principles.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:03,000 --> 00:01:08,000
|
| 59 |
+
Some of them will learn in this lesson and some of them will learn in other lessons from this section.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:09,000 --> 00:01:14,000
|
| 63 |
+
But before we start investigating each particular principle, let's define the problem first.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:16,000
|
| 67 |
+
While working on a class there.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:16,000 --> 00:01:22,000
|
| 71 |
+
Many design decisions that you apply in the classes you produce contain what you expect them to contain.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:23,000 --> 00:01:28,000
|
| 75 |
+
You can investigate each class and easily understand what this class was designed for and what it is
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:28,000 --> 00:01:29,000
|
| 79 |
+
intended to do.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:30,000 --> 00:01:34,000
|
| 83 |
+
And Gradney As you develop your application, you start group classes.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:34,000 --> 00:01:37,000
|
| 87 |
+
You may want to group them based on different reasons.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:37,000 --> 00:01:43,000
|
| 91 |
+
Some of them are classes, are part of one feature and serves the same idea or classes do something
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:43,000 --> 00:01:45,000
|
| 95 |
+
specific in similar way.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:45,000 --> 00:01:51,000
|
| 99 |
+
And it is logically to keep them together was intended to work with the same separate code in different
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:51,000 --> 00:01:57,000
|
| 103 |
+
programming languages, your group and classes in packages, namespace its components, etc..
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:57,000 --> 00:02:02,000
|
| 107 |
+
So let's agree that they would use such common terms as module or component.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:02,000 --> 00:02:08,000
|
| 111 |
+
That would mean some folder in the file directory, which is created to avoid name conflicts and to
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:08,000 --> 00:02:09,000
|
| 115 |
+
write a better maintainable code.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:10,000 --> 00:02:16,000
|
| 119 |
+
Hope this will make a terminology the same for different programming languages in the same way as you
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:16,000 --> 00:02:18,000
|
| 123 |
+
are conscious about the way you design your classes.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:19,000 --> 00:02:24,000
|
| 127 |
+
You immediately start asking yourself some questions about the design of the modules you create where
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:24,000 --> 00:02:30,000
|
| 131 |
+
it is better to put this class in which module may I put it in existing module or it is better to create
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:30,000 --> 00:02:31,000
|
| 135 |
+
a new one.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:31,000 --> 00:02:35,000
|
| 139 |
+
Should they split this component or it is not big enough yet.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:35,000 --> 00:02:39,000
|
| 143 |
+
It is okay if my model will depend on classes from another module.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:39,000 --> 00:02:45,000
|
| 147 |
+
Good module structure and confidence design will come from answers on such questions as does my new
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:45,000 --> 00:02:48,000
|
| 151 |
+
class belong to this specific module?
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:48,000 --> 00:02:55,000
|
| 155 |
+
Or now is it a self to create dependency on this component or know what is needed to be done to increase
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:55,000 --> 00:02:56,000
|
| 159 |
+
the ability of a module?
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:57,000 --> 00:03:00,000
|
| 163 |
+
What can I do to create a structure which is easy to maintain?
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:01,000 --> 00:03:04,000
|
| 167 |
+
Why do I need to worry about good structure and organization?
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:05,000 --> 00:03:09,000
|
| 171 |
+
Good code organization can use the tax benefits readability.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:09,000 --> 00:03:15,000
|
| 175 |
+
We now should forget that during software implementation, people create software for people's needs,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:15,000 --> 00:03:20,000
|
| 179 |
+
not only computers with our code, other people also reading our code.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:21,000 --> 00:03:26,000
|
| 183 |
+
You can save a lot of time for colleague of yours and money for your company in case, quote, will
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:26,000 --> 00:03:27,000
|
| 187 |
+
be understandable.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:28,000 --> 00:03:30,000
|
| 191 |
+
Each engineer should feel where to expect what.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:31,000 --> 00:03:37,000
|
| 195 |
+
Ask yourself how much time does it take to understand new project or even class, which you have never
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:37,000 --> 00:03:38,000
|
| 199 |
+
seen before?
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:38,000 --> 00:03:46,000
|
| 203 |
+
In some cases, this can take up to 50 percent of total time reserved for development making code readable.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:46,000 --> 00:03:52,000
|
| 207 |
+
It is one of the key factors of team performance and quality for large software projects with many developers
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:52,000 --> 00:03:58,000
|
| 211 |
+
and everywhere where the source code that was written by one person is going to be modified by another
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:58,000 --> 00:03:58,000
|
| 215 |
+
person.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:59,000 --> 00:04:06,000
|
| 219 |
+
Modularity modularity is not only about code organization, it is also about actual dependencies between
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:06,000 --> 00:04:08,000
|
| 223 |
+
the modules called in.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:08,000 --> 00:04:15,000
|
| 227 |
+
An application might be separated into modules and can even look like modular when in fact it is not.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:15,000 --> 00:04:20,000
|
| 231 |
+
Even despite multiple modules packages, name spaces are created.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:20,000 --> 00:04:26,000
|
| 235 |
+
Units in your code may still have complex interdependencies with other parts of your application and
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:26,000 --> 00:04:32,000
|
| 239 |
+
can still expose its private details so they will learn core principles which will help you to stick
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:32,000 --> 00:04:33,000
|
| 243 |
+
to modular approach.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:34,000 --> 00:04:41,000
|
| 247 |
+
Reusability, when software is reusable, it turns into increased productivity and quality, along with
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:41,000 --> 00:04:48,000
|
| 251 |
+
minimization of risk accurate during implementation of a new project or feature within the same project.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:49,000 --> 00:04:53,000
|
| 255 |
+
Software is a beauty, doesn't depend only on classes you implemented.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:54,000 --> 00:04:59,000
|
| 259 |
+
This property of your software includes all units and entities of your software, including modules,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:00,000 --> 00:05:01,000
|
| 263 |
+
reusability and software.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:01,000 --> 00:05:08,000
|
| 267 |
+
Development encourages innovation in traditional development methods and what it's also worth to mention
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:08,000 --> 00:05:14,000
|
| 271 |
+
that software is a beautiful decrease in project costs proportional to amount of code which was reused.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:14,000 --> 00:05:16,000
|
| 275 |
+
How to establish good code structure?
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:17,000 --> 00:05:23,000
|
| 279 |
+
What are key points that we should always remember while establishing a good structure on your project?
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:23,000 --> 00:05:27,000
|
| 283 |
+
Remember that this activity can bring benefit when it is experience based.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:27,000 --> 00:05:34,000
|
| 287 |
+
First of all, usually different business domains like banking, insurance, health care, e-commerce
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:34,000 --> 00:05:37,000
|
| 291 |
+
are limited with constraints of business use cases.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:37,000 --> 00:05:44,000
|
| 295 |
+
For example, it is highly unlikely that in banking software you would need to implement a search feature
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:44,000 --> 00:05:46,000
|
| 299 |
+
which is usually used in e-commerce domain.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:46,000 --> 00:05:53,000
|
| 303 |
+
Thus, in some degree, based on your experience, you can imagine how any system will look like this
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:53,000 --> 00:05:56,000
|
| 307 |
+
will help you to establish better cost structure from the very beginning.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:57,000 --> 00:06:03,000
|
| 311 |
+
Today, we'll discuss patterns and recommendations to follow, but they knew nothing if you are blindly
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:03,000 --> 00:06:04,000
|
| 315 |
+
following them.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:04,000 --> 00:06:12,000
|
| 319 |
+
Each project is unique and therefore the result of each project is unique and cost of each project is
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:12,000 --> 00:06:12,000
|
| 323 |
+
unique to.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:13,000 --> 00:06:19,000
|
| 327 |
+
Don't be afraid to experiment with things before applying some conventions this year that they are applicable
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:19,000 --> 00:06:21,000
|
| 331 |
+
directly to your project.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:21,000 --> 00:06:28,000
|
| 335 |
+
You should not forget that if refactoring or project restriction does not simplify things and make it
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:28,000 --> 00:06:31,000
|
| 339 |
+
even harder to understand, the initial goal is not achieved.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:32,000 --> 00:06:36,000
|
| 343 |
+
Ask yourself, can you come quickly grasp this project?
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:36,000 --> 00:06:42,000
|
| 347 |
+
All attempts to structure your code according to best practices and patterns should end up with clearer
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:42,000 --> 00:06:44,000
|
| 351 |
+
design, which is easy to understand.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:45,000 --> 00:06:48,000
|
| 355 |
+
Be consistent while applying the rules and patterns.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:48,000 --> 00:06:52,000
|
| 359 |
+
For example, use the same name everywhere across your project.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:52,000 --> 00:06:58,000
|
| 363 |
+
And remember, the sooner you start thinking about construction, the less refactoring is needed later.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:59,000 --> 00:07:02,000
|
| 367 |
+
There is no silver bullet for clean design and good structure.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:03,000 --> 00:07:05,000
|
| 371 |
+
As we already discussed, each project is unique.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:06,000 --> 00:07:11,000
|
| 375 |
+
Always there are different factors which impacts your deliverables and we have to consider while project
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:11,000 --> 00:07:15,000
|
| 379 |
+
implementation to name a few module cohesion.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:15,000 --> 00:07:21,000
|
| 383 |
+
And Coplin hope you already know what it is in case these terms are not familiar to you.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:21,000 --> 00:07:27,000
|
| 387 |
+
Make sure you watched my lesson about carbon and cohesion, cohesion and carbon and deal with the quality
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:27,000 --> 00:07:29,000
|
| 391 |
+
of an object oriented design.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:29,000 --> 00:07:35,000
|
| 395 |
+
One of the key principles that we all know that to create maintainable code we need to follow simple
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:35,000 --> 00:07:37,000
|
| 399 |
+
rule, low carbon and high cohesion.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:38,000 --> 00:07:44,000
|
| 403 |
+
When we are talking about low carbon, we want to put stress on separation of unrelated parts of the
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:44,000 --> 00:07:46,000
|
| 407 |
+
code as much as we can.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:46,000 --> 00:07:51,000
|
| 411 |
+
And when we refer to high cohesion, we mean keeping the related code in a single place.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:52,000 --> 00:07:53,000
|
| 415 |
+
What is the main goal of the rule?
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:54,000 --> 00:08:01,000
|
| 419 |
+
The aim of design was low carbon and high cohesion is to simplify the development process, to simplify
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:01,000 --> 00:08:06,000
|
| 423 |
+
code base maintenance, simplify addition of new features, make it less fragile.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:06,000 --> 00:08:12,000
|
| 427 |
+
While is straightforward in theory, it is not always easy to follow it in real life.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:12,000 --> 00:08:16,000
|
| 431 |
+
Today will review principles with you, which will help you to adhere through.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:17,000 --> 00:08:24,000
|
| 435 |
+
The second factor is probably code based growth since software consider it to be deprecated by the time
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:24,000 --> 00:08:25,000
|
| 439 |
+
it will be released.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:25,000 --> 00:08:29,000
|
| 443 |
+
We constantly evolve our vision of the product during its implementation.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:30,000 --> 00:08:36,000
|
| 447 |
+
You have to consider potential change factors which might pop up and be prepared for corn based growth
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:36,000 --> 00:08:38,000
|
| 451 |
+
as new feature will be added to your project.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:39,000 --> 00:08:43,000
|
| 455 |
+
The next factor is team organization and communication between team members.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:43,000 --> 00:08:46,000
|
| 459 |
+
This very important factor for your project structure.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:47,000 --> 00:08:48,000
|
| 463 |
+
Right?
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:48,000 --> 00:08:54,000
|
| 467 |
+
And this course will discuss Conway's law and will analyze how a team composition might influence project
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:54,000 --> 00:08:55,000
|
| 471 |
+
code structure.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:56,000 --> 00:09:00,000
|
| 475 |
+
Technical factors can also impact your code structure in some way.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:00,000 --> 00:09:07,000
|
| 479 |
+
Also, during the course, I will show you examples to demonstrate how technical limitations might impact
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:07,000 --> 00:09:08,000
|
| 483 |
+
our project structure.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:08,000 --> 00:09:14,000
|
| 487 |
+
And at the end of the day, our goal is to make navigation in your project easier and predictable.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:14,000 --> 00:09:18,000
|
| 491 |
+
There is no intention to make your cost structure harder to navigate.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:18,000 --> 00:09:23,000
|
| 495 |
+
And after applying patterns, which we'll discuss in this course, let's start from Cohesion Principles
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:23,000 --> 00:09:25,000
|
| 499 |
+
of Growth Organization.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:25,000 --> 00:09:30,000
|
| 503 |
+
But before we start, let's recap definition of cohesion and understand what is modules.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:30,000 --> 00:09:31,000
|
| 507 |
+
Cohesion.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:31,000 --> 00:09:34,000
|
| 511 |
+
Cohesion refers to the degree to which the.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:34,000 --> 00:09:37,000
|
| 515 |
+
Elements of a specific component belong to Gaza.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:37,000 --> 00:09:41,000
|
| 519 |
+
It is about items which can exist and do one thing well together.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:42,000 --> 00:09:48,000
|
| 523 |
+
So cohesion is about the way how we can group our code that contributes to a single task together.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:49,000 --> 00:09:54,000
|
| 527 |
+
Also, cohesion indicates the degree to which a module has a single, more focused purpose.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:55,000 --> 00:09:58,000
|
| 531 |
+
There are many benefits which we expect to get from high cohesion.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:58,000 --> 00:10:02,000
|
| 535 |
+
Some of them maintenance of highly cohesive units is much easier.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:03,000 --> 00:10:06,000
|
| 539 |
+
Highly cohesive items are less frequently changed.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:06,000 --> 00:10:12,000
|
| 543 |
+
Reusability, reusability of such modules is higher because they are designed to serve a well focused
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:12,000 --> 00:10:18,000
|
| 547 |
+
purpose and want you to understand module cohesion as a concept which will help you to compose your
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:18,000 --> 00:10:22,000
|
| 551 |
+
components the way they become reusable and easily maintainable.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:22,000 --> 00:10:28,000
|
| 555 |
+
The three major module cohesion principles which we are going to review today, they are common closure
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:28,000 --> 00:10:35,000
|
| 559 |
+
principle, common reuse principle and reuse release equivalence while choosing the classes which should
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:35,000 --> 00:10:42,000
|
| 563 |
+
be grouped together to opposing forces related to software usability and develop ability must be taken
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:42,000 --> 00:10:43,000
|
| 567 |
+
into consideration.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:43,000 --> 00:10:46,000
|
| 571 |
+
It is not an easy task to balance these forces.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:46,000 --> 00:10:48,000
|
| 575 |
+
Usually this balance is dynamic.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:49,000 --> 00:10:56,000
|
| 579 |
+
Has our module structure will evolve as focus of project shifts from develop ability to reusability
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:57,000 --> 00:10:59,000
|
| 583 |
+
and we start from the common closure principle.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:59,000 --> 00:11:05,000
|
| 587 |
+
This principle states that the classes in the module should be close together against the same kinds
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:05,000 --> 00:11:12,000
|
| 591 |
+
of changes and changes that affects Amodeo, affects all the classes in that module and no other modules.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:13,000 --> 00:11:18,000
|
| 595 |
+
You can treat common closure principles the same as single responsibility principle, but just related
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:18,000 --> 00:11:19,000
|
| 599 |
+
to competence.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:20,000 --> 00:11:25,000
|
| 603 |
+
It is obvious that from the maintenance standpoint, changes which might impact as a module since the
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:25,000 --> 00:11:31,000
|
| 607 |
+
application is not avoidable, but they should be controlled or at least minimized.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:31,000 --> 00:11:38,000
|
| 611 |
+
The main idea here is in case change has been made in one module rerelease or invalidating of other
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:38,000 --> 00:11:42,000
|
| 615 |
+
modules that are not dependent on the changed one is not needed.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:42,000 --> 00:11:49,000
|
| 619 |
+
Similarly, the single responsibility principle for classes, the closure principle, states that the
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:49,000 --> 00:11:52,000
|
| 623 |
+
classes in the module should not have different reasons to change.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:53,000 --> 00:11:59,000
|
| 627 |
+
If there is a need to make a change or to implement a new feature, it will be better to make changes
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:59,000 --> 00:12:03,000
|
| 631 |
+
in one module rather than making changes in multiple different modules.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:04,000 --> 00:12:08,000
|
| 635 |
+
It is natural that the classes at the tightly related will change together.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:08,000 --> 00:12:14,000
|
| 639 |
+
Thus, in case we keep classes that are tightly related together in one module, only one module, a
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:14,000 --> 00:12:18,000
|
| 643 |
+
very small number of them are going to be affected when a change happens.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:18,000 --> 00:12:25,000
|
| 647 |
+
And also in this case, all activity is targeted to revalidation and the reason will be decreased when
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:25,000 --> 00:12:26,000
|
| 651 |
+
this slide.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:26,000 --> 00:12:31,000
|
| 655 |
+
You can see that, for example, changes in the interface of Bill and other stip most likely will cause
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:31,000 --> 00:12:33,000
|
| 659 |
+
changes in invoice type.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:33,000 --> 00:12:34,000
|
| 663 |
+
There's very low.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:34,000 --> 00:12:39,000
|
| 667 |
+
Chances are changes in billing address type will cause changes in customer time.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:39,000 --> 00:12:45,000
|
| 671 |
+
It is also worth to mention that this principle is closely associated with the open closed principle.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:45,000 --> 00:12:52,000
|
| 675 |
+
You know that open closed principle states that classes should be closed for modification but open for
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:52,000 --> 00:12:53,000
|
| 679 |
+
extension.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:53,000 --> 00:12:57,000
|
| 683 |
+
But in real life, 100 percent closure is not attainable.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:57,000 --> 00:12:59,000
|
| 687 |
+
Closure must be strategic.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:59,000 --> 00:13:05,000
|
| 691 |
+
We design our code modules in such a way that they are close to the most common kinds of changes that
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:05,000 --> 00:13:07,000
|
| 695 |
+
we have experienced.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:07,000 --> 00:13:13,000
|
| 699 |
+
If we review common closure principle from open closed principle point of view, we can say that modules
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:13,000 --> 00:13:17,000
|
| 703 |
+
should be closed against the same kinds of changes in specific.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:17,000 --> 00:13:23,000
|
| 707 |
+
This means that in case we are going to change some code in our module, it is most likely that the
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:23,000 --> 00:13:26,000
|
| 711 |
+
requested change will affect only one module.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:26,000 --> 00:13:32,000
|
| 715 |
+
And contrariwise, when the changes are requested and this change affects one module most likely is
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:32,000 --> 00:13:35,000
|
| 719 |
+
that all classes inside that module will be affected.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:36,000 --> 00:13:42,000
|
| 723 |
+
This principle allows us to limit amount of modules that are affected by any changes to the smallest
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:42,000 --> 00:13:43,000
|
| 727 |
+
possible number.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:44,000 --> 00:13:50,000
|
| 731 |
+
Imagine also the case that people, while implementing their features or projects, create a dependency
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:50,000 --> 00:13:56,000
|
| 735 |
+
on your module and most likely that people want to track all new releases of your module to keep their
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:56,000 --> 00:13:57,000
|
| 739 |
+
code up to date.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:57,000 --> 00:14:03,000
|
| 743 |
+
After you released new version of your module, clients of your code will update that project, but
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:03,000 --> 00:14:06,000
|
| 747 |
+
they will proceed with upgrade only in case they would know.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:06,000 --> 00:14:12,000
|
| 751 |
+
The changes you made to the module in the latest release impacts the way how module is used in the project,
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:12,000 --> 00:14:16,000
|
| 755 |
+
because every such a great requires them to perform validation.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:16,000 --> 00:14:19,000
|
| 759 |
+
That existing code base still works as expected.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:19,000 --> 00:14:25,000
|
| 763 |
+
With the new version of your module being a model maintenance, you should follow the common closure
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:25,000 --> 00:14:31,000
|
| 767 |
+
principle to prevent yourself from opening a module for all kinds of unrelated reasons.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:32,000 --> 00:14:38,000
|
| 771 |
+
The next principle, which we are going to review is commonly used principle, this principle states
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:38,000 --> 00:14:41,000
|
| 775 |
+
that classes in the module are used together.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:41,000 --> 00:14:45,000
|
| 779 |
+
If you use one of the classes in the module, you reuse them all.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:46,000 --> 00:14:52,000
|
| 783 |
+
You need to be aware that there are always to adjust, that you need to avoid while grouping classes
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:52,000 --> 00:14:53,000
|
| 787 |
+
into modules.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:53,000 --> 00:14:58,000
|
| 791 |
+
The first ATCH is that you can implement a lot of amazing classes features.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:58,000 --> 00:15:04,000
|
| 795 |
+
These classes might be very useful and super helpful, but if you will release all of these classes
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:04,000 --> 00:15:10,000
|
| 799 |
+
as one module, this would mean that the class of your code should put a dependency on the entire module
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:10,000 --> 00:15:14,000
|
| 803 |
+
and will be forced to be dependent on classes they don't use.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:15,000 --> 00:15:20,000
|
| 807 |
+
So even if clients of your code use only a few classes from your module, which is a very small part
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:20,000 --> 00:15:24,000
|
| 811 |
+
of it, they still need to pull and try module into their project.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:24,000 --> 00:15:26,000
|
| 815 |
+
This is quite a maintenance burden for them.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:27,000 --> 00:15:32,000
|
| 819 |
+
On the other hand, you can't put each single class in a separate module.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:32,000 --> 00:15:35,000
|
| 823 |
+
First of all, this has no any sense.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:35,000 --> 00:15:39,000
|
| 827 |
+
And at the end of the day, you would need to release tons of modules.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:39,000 --> 00:15:41,000
|
| 831 |
+
This includes your own maintenance burden.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:42,000 --> 00:15:45,000
|
| 835 |
+
In this case, your clients now Bozarth with other issues.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:45,000 --> 00:15:50,000
|
| 839 |
+
They have a huge list of dependencies and they need to keep track of changes and new releases of all
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:50,000 --> 00:15:51,000
|
| 843 |
+
these modules.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:52,000 --> 00:15:59,000
|
| 847 |
+
This principle tells us which classes should be grouped together as it states the classes that tend
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:15:59,000 --> 00:16:02,000
|
| 851 |
+
to be used together should be in the same module.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:02,000 --> 00:16:09,000
|
| 855 |
+
It is more likely for reuseable classes to depend on each other, so classes are really reused and separation.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:09,000 --> 00:16:16,000
|
| 859 |
+
The principle states that the classes of a module should be inseparable, which means that if module
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:16,000 --> 00:16:22,000
|
| 863 |
+
depends on another one, it should depend on all of its classes and not on a number of them.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:23,000 --> 00:16:29,000
|
| 867 |
+
Insured classes that are not tightly coupled to each other should not be kept in the same module.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:30,000 --> 00:16:36,000
|
| 871 |
+
And this also needs to be mentioned that the common reuse principle puts stress not only on classes
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:36,000 --> 00:16:42,000
|
| 875 |
+
which we need to put together in the module, but it also tells us what classes not to put in the module
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:43,000 --> 00:16:46,000
|
| 879 |
+
one in one module using class from another one.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:46,000 --> 00:16:49,000
|
| 883 |
+
This doesn't weaken the dependency between modules at all.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:50,000 --> 00:16:57,000
|
| 887 |
+
Modules are still dependent on each other and now every time used to module is released, the using
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:57,000 --> 00:17:03,000
|
| 891 |
+
modules must be revalidated and the rereleased usually modules have physical representations and shared
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:17:03,000 --> 00:17:09,000
|
| 895 |
+
libraries like DLs or Jar's, if they use the module is released as a jar.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:17:09,000 --> 00:17:16,000
|
| 899 |
+
Zinser using code depends on the entire jar and a modification to the jar, even to one class, will
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:16,000 --> 00:17:20,000
|
| 903 |
+
still cause a new version of the jar to be released.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:21,000 --> 00:17:27,000
|
| 907 |
+
This principle might look pretty straightforward and obvious at first glance, just put glasses that
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:27,000 --> 00:17:29,000
|
| 911 |
+
are going to be used together in one module.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:29,000 --> 00:17:33,000
|
| 915 |
+
It is even hard to put completely unrelated clauses that are never used together.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:34,000 --> 00:17:39,000
|
| 919 |
+
But things become less obvious when we consider the fact we should not put classes in one module that
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:39,000 --> 00:17:41,000
|
| 923 |
+
are not used together.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:41,000 --> 00:17:47,000
|
| 927 |
+
We also need to think about classes that are likely not to be used together in the future.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:47,000 --> 00:17:53,000
|
| 931 |
+
In the example on the slide, you can see that we are sure that we don't want to put string could use
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:53,000 --> 00:17:57,000
|
| 935 |
+
item in one module next to an address and invoice items.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:57,000 --> 00:17:58,000
|
| 939 |
+
Why?
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:58,000 --> 00:18:04,000
|
| 943 |
+
Because we are not sure that every time we will reuse billing, address and invoice in other places
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:04,000 --> 00:18:06,000
|
| 947 |
+
of our software, we would need details.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:07,000 --> 00:18:12,000
|
| 951 |
+
We are also not sure that to could use an invoice and billing address always used together.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:13,000 --> 00:18:19,000
|
| 955 |
+
And we don't want to force clients of our component to depend on all changes in strangelet.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:19,000 --> 00:18:20,000
|
| 959 |
+
Use CLOs.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:20,000 --> 00:18:26,000
|
| 963 |
+
That's why it is better to keep trying to use outside of the module, because each update of external
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:26,000 --> 00:18:31,000
|
| 967 |
+
library will require regression testing of the whole system.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:31,000 --> 00:18:37,000
|
| 971 |
+
One more important principle related to module cohesion is reuse release equivalence principle.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:37,000 --> 00:18:46,000
|
| 975 |
+
This principle states that the granting of reuse is a granule of this principle also brings us to conclusion
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:46,000 --> 00:18:50,000
|
| 979 |
+
that if you use are going to be released together, they should be in the one module.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:51,000 --> 00:18:57,000
|
| 983 |
+
That's why the size of the code that is intended to be reused is the same as size of the release module.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:58,000 --> 00:19:04,000
|
| 987 |
+
This principle is different from common reuse principle, but you might be wondering what is the difference?
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:04,000 --> 00:19:10,000
|
| 991 |
+
The main difference is that the stress in common reuse principle is put on reusing units from the same
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:10,000 --> 00:19:18,000
|
| 995 |
+
module together, whereas in reuse release equivalence principle stresses put on reusing of the whole
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:18,000 --> 00:19:18,000
|
| 999 |
+
module.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:19,000 --> 00:19:25,000
|
| 1003 |
+
When you project become more mature and it is time to release your code, you start thinking about what
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:25,000 --> 00:19:26,000
|
| 1007 |
+
modules should be released first.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:27,000 --> 00:19:32,000
|
| 1011 |
+
And the answer to this question impacts the way how you approach your code organization.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:32,000 --> 00:19:37,000
|
| 1015 |
+
You need to understand that the code which will be released together, will be reused together.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:38,000 --> 00:19:44,000
|
| 1019 |
+
The code, which will be released together, will be maintained together as the project will grow.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:44,000 --> 00:19:50,000
|
| 1023 |
+
The weight of this principle will become more because at the end of the day, you are not able to follow
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:50,000 --> 00:19:52,000
|
| 1027 |
+
all cohesion principles 100 percent.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:53,000 --> 00:19:59,000
|
| 1031 |
+
There's always a matter of the tradeoffs and balance between all cohesion principles, and you understand
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:59,000 --> 00:20:05,000
|
| 1035 |
+
that sometimes it makes sense to put units together in one module if they are going to be released together
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:05,000 --> 00:20:11,000
|
| 1039 |
+
and not necessarily it will be used in conjunction is a good example of this principle is Java util
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:11,000 --> 00:20:12,000
|
| 1043 |
+
package in JDK.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:12,000 --> 00:20:19,000
|
| 1047 |
+
It contains a lot of units which are often unrelated, such as collections, interfaces, classes to
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:20:19,000 --> 00:20:24,000
|
| 1051 |
+
work with date classes to work with the application locale with random number generation.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:25,000 --> 00:20:31,000
|
| 1055 |
+
But the goal was to release module, which will be commonly reused across different Java applications.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:31,000 --> 00:20:35,000
|
| 1059 |
+
We learned a lot in this lesson and we still have a lot of things to learn.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:35,000 --> 00:20:37,000
|
| 1063 |
+
The current code grouping and packaging.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:38,000 --> 00:20:42,000
|
| 1067 |
+
Namely, we still need to learn Coplan principles during the course group.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:42,000 --> 00:20:46,000
|
| 1071 |
+
And what I suggest to cover this is a separate lesson take into account.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:46,000 --> 00:20:48,000
|
| 1075 |
+
We have already learnt a lot.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:48,000 --> 00:20:52,000
|
| 1079 |
+
Let's recap what we have learned today after this lesson.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:52,000 --> 00:20:59,000
|
| 1083 |
+
You understand why we need a good structure and why question how to group classes in one module is important
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:59,000 --> 00:21:02,000
|
| 1087 |
+
review of the factors that will impact good structure.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:21:03,000 --> 00:21:05,000
|
| 1091 |
+
And we review three cohesion principles.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:21:05,000 --> 00:21:11,000
|
| 1095 |
+
They are common closure principle, common reuse principle and reuse equivalence principle.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:21:12,000 --> 00:21:17,000
|
| 1099 |
+
I want to put stress on the fact that they are a very important lesson and I hope you loved it.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:18,000 --> 00:21:21,000
|
| 1103 |
+
Will learn module structure further in the course.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:21,000 --> 00:21:23,000
|
| 1107 |
+
Thanks a lot for your attention.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:23,000 --> 00:21:25,000
|
| 1111 |
+
See you in the next lesson.
|
| 1112 |
+
|
38 - Object-oriented Architecture, Clean Code Design (Advanced)/009 Packaging Pricniples p.2 Coupling Principles and Others_en.srt
ADDED
|
@@ -0,0 +1,1320 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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,000 --> 00:00:06,000
|
| 3 |
+
Hello, Jim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:12,000
|
| 7 |
+
And this lesson will proceed, learning, packaging principles, namely, we'll talk about Coplin packaging
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:14,000
|
| 11 |
+
principles, I will explain.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:14,000 --> 00:00:20,000
|
| 15 |
+
It was example's next KAPLIN principles, acyclic dependencies, principle, stable dependencies and
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:20,000 --> 00:00:22,000
|
| 19 |
+
stable abstractions principle.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:22,000 --> 00:00:28,000
|
| 23 |
+
Also in this lesson, we'll talk about other approaches during construction that is good to know and
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:28,000 --> 00:00:29,000
|
| 27 |
+
apply in practice.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:29,000 --> 00:00:32,000
|
| 31 |
+
I will explain your package, bilayer and package by feature.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:33,000 --> 00:00:38,000
|
| 35 |
+
After that, we'll discuss how team structure may impact your cost structure and that will explain your
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:38,000 --> 00:00:44,000
|
| 39 |
+
Conways law will review technical factors that may impact cost structure and at the end of the class.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:44,000 --> 00:00:49,000
|
| 43 |
+
And we'll talk about tools for code analysis that may help to keep your code clean.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:49,000 --> 00:00:54,000
|
| 47 |
+
So let's try to understand context and background for complete package and principles.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:54,000 --> 00:01:00,000
|
| 51 |
+
Understanding these rules will help us to understand the logic that stands behind each of these principles.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:01,000 --> 00:01:06,000
|
| 55 |
+
Our application usually tend to be large networks of interrelated modules.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:06,000 --> 00:01:12,000
|
| 59 |
+
That is why it is very important to find some partners and create rules that will govern this interrelationship
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:12,000 --> 00:01:14,000
|
| 63 |
+
and object oriented architecture.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:19,000
|
| 67 |
+
The next three principles, which we are going to discuss today focus on the interrelationships between
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:19,000 --> 00:01:20,000
|
| 71 |
+
modules.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:20,000 --> 00:01:23,000
|
| 75 |
+
We already learned what Kopplin is in another lesson.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:23,000 --> 00:01:27,000
|
| 79 |
+
In case you missed that lesson, take your time to watch it.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:27,000 --> 00:01:32,000
|
| 83 |
+
But nevertheless, before we start to discuss these principles, let's recap first what Koplin.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:32,000 --> 00:01:34,000
|
| 87 |
+
S Kopplin is.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:34,000 --> 00:01:40,000
|
| 91 |
+
The degree of interdependence between software modules and measure of how closely connected to modules
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:40,000 --> 00:01:44,000
|
| 95 |
+
are the strengths of the relationships between modules.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:45,000 --> 00:01:48,000
|
| 99 |
+
Coplin consider it to be the principle of separation of concerns.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:49,000 --> 00:01:49,000
|
| 103 |
+
What does it mean?
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:50,000 --> 00:01:56,000
|
| 107 |
+
This means that one module should not directly affect or modify the state or behaviour of another module.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:57,000 --> 00:02:02,000
|
| 111 |
+
Company pays attention to the relationship between modules and how closely connected they are.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:03,000 --> 00:02:07,000
|
| 115 |
+
To make you understand Coplan better, let's consider the next example.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:08,000 --> 00:02:12,000
|
| 119 |
+
Tamou and C assess before to assess appeared.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:12,000 --> 00:02:15,000
|
| 123 |
+
Temel was used for both Mark-Up and presentation.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:15,000 --> 00:02:22,000
|
| 127 |
+
This ended up with creation of huge files and bloated code that was difficult to maintain and extremely
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:22,000 --> 00:02:29,000
|
| 131 |
+
hard to change with the advent of T says two concerns markup and presentation have been separated.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:30,000 --> 00:02:35,000
|
| 135 |
+
After that, H.T. email became in charge of only a markup and this became used for presentation.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:36,000 --> 00:02:39,000
|
| 139 |
+
This separation made the code cleaner and easier to change.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:40,000 --> 00:02:42,000
|
| 143 |
+
Why lose company considered to be good?
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:42,000 --> 00:02:49,000
|
| 147 |
+
Because Loose Kaplin led the court to be more changeable, easier to work with, and more flexible modules
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:49,000 --> 00:02:52,000
|
| 151 |
+
that rely on another wants and can modify.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:52,000 --> 00:02:59,000
|
| 155 |
+
The status of other modules are set to be tightly coupled with might cause the issues because high Coplan
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:59,000 --> 00:03:06,000
|
| 159 |
+
can cause so-called ripple effect when modification of code from one module also requires code changes
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:06,000 --> 00:03:07,000
|
| 163 |
+
to be done in another one.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:08,000 --> 00:03:13,000
|
| 167 |
+
Where is the ability of code which is tightly coupled is also significantly decreased because code is
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:13,000 --> 00:03:15,000
|
| 171 |
+
harder to separate from each other.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:16,000 --> 00:03:21,000
|
| 175 |
+
So the rule of thumb sounds like this strive for low carbon and high cohesion.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:21,000 --> 00:03:28,000
|
| 179 |
+
This rule is a reminder for us that we should strive for code that separates tasks and doesn't rely
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:28,000 --> 00:03:29,000
|
| 183 |
+
heavily on each other.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:29,000 --> 00:03:33,000
|
| 187 |
+
That is why low carbon generally considered to be a good thing.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:33,000 --> 00:03:40,000
|
| 191 |
+
While high coupling is generally bad, the next principle will help us to achieve architecture with
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:40,000 --> 00:03:45,000
|
| 195 |
+
low coupling, as it was stated in agenda will focus on three principles.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:45,000 --> 00:03:51,000
|
| 199 |
+
I seek dependencies, principle, stable dependencies, principle and stable abstractions principle.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:51,000 --> 00:03:54,000
|
| 203 |
+
Let's discuss each of these principles one by one.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:55,000 --> 00:04:00,000
|
| 207 |
+
The first Kopplin Principle, which we are going to review today, is acyclic dependencies principle.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:01,000 --> 00:04:05,000
|
| 211 |
+
This principle says allowing all cycles in the component dependency graph.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:06,000 --> 00:04:12,000
|
| 215 |
+
The dependencies principle is the first of three principles that deals with the relationships between
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:12,000 --> 00:04:12,000
|
| 219 |
+
components.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:13,000 --> 00:04:16,000
|
| 223 |
+
How to check that you have cyclic dependency in your app.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:16,000 --> 00:04:21,000
|
| 227 |
+
If you draw the components and the dependencies between them and you are able to follow a dependency
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:21,000 --> 00:04:24,000
|
| 231 |
+
back to component, you have already visited them.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:24,000 --> 00:04:26,000
|
| 235 |
+
It is validation to ADP.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:27,000 --> 00:04:28,000
|
| 239 |
+
But what do we need to strive for?
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:29,000 --> 00:04:32,000
|
| 243 |
+
We always try to implement directed a secret graph.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:33,000 --> 00:04:35,000
|
| 247 |
+
So why should you care about secret dependencies?
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:35,000 --> 00:04:42,000
|
| 251 |
+
Because their existence makes it very hard to split up responsibilities and work on different tasks
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:42,000 --> 00:04:45,000
|
| 255 |
+
in parallel without stepping on each other's toes all the time.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:46,000 --> 00:04:49,000
|
| 259 |
+
To understand these principles better, let's consider the next example.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:50,000 --> 00:04:57,000
|
| 263 |
+
You have a system which consists of the next modules, key front and this model where all automation
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:57,000 --> 00:04:58,000
|
| 267 |
+
tasks are stored.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:59,000 --> 00:05:03,000
|
| 271 |
+
Service interface, the module which expose an external interface to certain.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:04,000 --> 00:05:11,000
|
| 275 |
+
Utilities, the module with classes that helps us to perform some calculations domain the module which
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:11,000 --> 00:05:18,000
|
| 279 |
+
contains actual domain logic, this module depends on the eulogists module engineers who worked on YouTube.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:18,000 --> 00:05:24,000
|
| 283 |
+
This module realized that creative from module has amazing string manipulation activities that are already
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:24,000 --> 00:05:25,000
|
| 287 |
+
implemented.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:25,000 --> 00:05:28,000
|
| 291 |
+
And these engineers added a dependency.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:28,000 --> 00:05:34,000
|
| 295 |
+
Now etiologies module depends on key Front-End module and now you have cyclic dependency.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:35,000 --> 00:05:41,000
|
| 299 |
+
Everything worked fine until one day a colleague of yours updated the way housetrained Cucuta's worked
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:41,000 --> 00:05:42,000
|
| 303 |
+
for the sake of automated tests.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:43,000 --> 00:05:49,000
|
| 307 |
+
Next day I realized that the main module has broken logic and system behaves not as expected.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:49,000 --> 00:05:55,000
|
| 311 |
+
Definitely creating dependency between the coaches and from that module should be considered as an alarm,
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:56,000 --> 00:06:01,000
|
| 315 |
+
not only because your production code depends on key code in this case, but also because of cyclic
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:01,000 --> 00:06:06,000
|
| 319 |
+
dependency, which makes code development and support sometimes unpredictable.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:06,000 --> 00:06:07,000
|
| 323 |
+
And time-Consuming.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:07,000 --> 00:06:11,000
|
| 327 |
+
To foster better architecture design, we need to break cyclic dependency.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:12,000 --> 00:06:12,000
|
| 331 |
+
But how?
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:13,000 --> 00:06:14,000
|
| 335 |
+
There are two options how to break it.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:15,000 --> 00:06:20,000
|
| 339 |
+
The first option when you to apply the penalty inversion principle, for example, in this case, we
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:20,000 --> 00:06:23,000
|
| 343 |
+
could create an abstraction that is required for it.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:23,000 --> 00:06:26,000
|
| 347 |
+
You adjust more module, we can put this abstraction in it.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:26,000 --> 00:06:34,000
|
| 351 |
+
You just module had inherited in from this inverse dependency between liquidities and front end module.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:35,000 --> 00:06:41,000
|
| 355 |
+
The second option is to create a new module on which both front end and the utilities depend.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:41,000 --> 00:06:45,000
|
| 359 |
+
You can move the classes that they both depend on into that pneumonia.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:46,000 --> 00:06:52,000
|
| 363 |
+
The greatest danger of cyclic dependencies is that problems in one of your dependencies might backfire
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:52,000 --> 00:06:56,000
|
| 367 |
+
after they have travelled the entire cycle through the dependency graph.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:57,000 --> 00:07:02,000
|
| 371 |
+
Even when your dependency graph has no cycles, there is still a chance that dependency sophomore year
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:02,000 --> 00:07:05,000
|
| 375 |
+
will start causing problems at any time in the future.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:06,000 --> 00:07:11,000
|
| 379 |
+
Whenever you upgrade one of your projects dependencies, you hope that your project will still work
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:11,000 --> 00:07:12,000
|
| 383 |
+
as it did before.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:13,000 --> 00:07:18,000
|
| 387 |
+
However, there is always a risk that it suddenly starts to fail in unexpected ways.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:19,000 --> 00:07:23,000
|
| 391 |
+
The stable dependencies, principle says, depend in the direction of stability.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:24,000 --> 00:07:26,000
|
| 395 |
+
Design cannot be completely static.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:26,000 --> 00:07:29,000
|
| 399 |
+
We evolve our application constantly.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:29,000 --> 00:07:34,000
|
| 403 |
+
We apply the common closure principle to create modules that are sensitive to certain kinds of changes.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:35,000 --> 00:07:41,000
|
| 407 |
+
These modules are designed to be volatile, and we expect them to change the rule of thumb here as a
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:41,000 --> 00:07:48,000
|
| 411 |
+
module that we expect to be volatile should not be depended on by a module that is difficult to change.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:48,000 --> 00:07:54,000
|
| 415 |
+
By conforming to the stable dependencies principle, we ensure that the modules that are intended to
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:54,000 --> 00:07:59,000
|
| 419 |
+
be easy to change are not dependent on modules that are harder to change than they are.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:59,000 --> 00:08:03,000
|
| 423 |
+
But what is the magic to measure hardness of changes?
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:03,000 --> 00:08:10,000
|
| 427 |
+
There are many factors that make software component hard to change, some of them its size, complexity,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:10,000 --> 00:08:14,000
|
| 431 |
+
clarity, mission of the component, etc..
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:14,000 --> 00:08:17,000
|
| 435 |
+
But I would like to put focus on another metric.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:17,000 --> 00:08:23,000
|
| 439 |
+
The easiest way to make more difficult to change is to make lots of other software modules dependent
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:24,000 --> 00:08:25,000
|
| 443 |
+
on the diagram.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:25,000 --> 00:08:29,000
|
| 447 |
+
You can see pretty stable module doing stable modules depend on it.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:29,000 --> 00:08:34,000
|
| 451 |
+
We can say that pretty stable module already has two good reasons not to change.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:34,000 --> 00:08:40,000
|
| 455 |
+
If you expect module to be flexible and volatile, it is not the best idea to make a pretty stable module
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:40,000 --> 00:08:45,000
|
| 459 |
+
dependent on the flexible one because the last wheel becomes a module which is hard to change.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:46,000 --> 00:08:51,000
|
| 463 |
+
And remember the stable dependencies principle is not about making all modules stable.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:51,000 --> 00:08:57,000
|
| 467 |
+
It is impossible and at the end of the day is not needed because in case all modules are stable, that
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:57,000 --> 00:08:59,000
|
| 471 |
+
means the system is unchangeable.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:00,000 --> 00:09:06,000
|
| 475 |
+
Indeed, we want to design our module structure so that some modules unstable and some are stable,
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:06,000 --> 00:09:07,000
|
| 479 |
+
stable dependencies.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:07,000 --> 00:09:14,000
|
| 483 |
+
Principal emphasizes the necessity of the direction of the dependency between the modules from volatile
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:14,000 --> 00:09:15,000
|
| 487 |
+
modules to stable ones.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:16,000 --> 00:09:17,000
|
| 491 |
+
Does it make sense?
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:17,000 --> 00:09:19,000
|
| 495 |
+
If this is clear, I suggest to move on.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:20,000 --> 00:09:25,000
|
| 499 |
+
And the last but not the least principle related to module schöpflin is stable abstractions principle.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:26,000 --> 00:09:30,000
|
| 503 |
+
This principle states that the components should be as abstract as it is stable.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:31,000 --> 00:09:38,000
|
| 507 |
+
The name of the stable abstractions principle contains two important words stable and abstract from
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:38,000 --> 00:09:39,000
|
| 511 |
+
the dependency inversion principle.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:39,000 --> 00:09:44,000
|
| 515 |
+
You know that classes should depend on abstractions, not on concrete classes.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:44,000 --> 00:09:51,000
|
| 519 |
+
The similar way we want a couple our components, however, dependency, inversion principle deals with
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:51,000 --> 00:09:53,000
|
| 523 |
+
classes and with classes.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:53,000 --> 00:09:56,000
|
| 527 |
+
Everything is clear is a class is abstract or it is not.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:57,000 --> 00:10:03,000
|
| 531 |
+
So our stable module should also be abstract so that its stability doesn't prevent it from being.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:04,000 --> 00:10:11,000
|
| 535 |
+
On the other hand, in stable more, you should be concrete, since its instability allows the country
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:11,000 --> 00:10:13,000
|
| 539 |
+
to one within it to be easily changed.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:14,000 --> 00:10:20,000
|
| 543 |
+
That means if a model is planned to be stable according to design, it should contain abstract types
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:20,000 --> 00:10:23,000
|
| 547 |
+
in it so that it could be extended easily.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:23,000 --> 00:10:30,000
|
| 551 |
+
Stable modules that can be extended, though not overly constrain the design, but how to measure abstractness.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:30,000 --> 00:10:36,000
|
| 555 |
+
One of the possible calculations which you can do to identify abstraction of your component is to divide
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:36,000 --> 00:10:38,000
|
| 559 |
+
the number of abstract entities.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:38,000 --> 00:10:45,000
|
| 563 |
+
I mean abstract classes and interfaces in your component by a number of all classes in that have value
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:45,000 --> 00:10:50,000
|
| 567 |
+
of zero means that the component contains no abstract classes and value.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:50,000 --> 00:10:54,000
|
| 571 |
+
One means that components contains nothing but abstract entities.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:55,000 --> 00:11:01,000
|
| 575 |
+
So by this moment we have learned three cohesion and three Coplin principles that will help us to group
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:01,000 --> 00:11:02,000
|
| 579 |
+
our code.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:02,000 --> 00:11:07,000
|
| 583 |
+
But actually the other principles exist that will help you to structure your code.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:07,000 --> 00:11:08,000
|
| 587 |
+
Let's review some of them.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:09,000 --> 00:11:13,000
|
| 591 |
+
There are many ways how to organize the classes into modules in software project.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:14,000 --> 00:11:20,000
|
| 595 |
+
I also want to review with you pros and cons of your popular ways of how to group classes in your app.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:20,000 --> 00:11:25,000
|
| 599 |
+
One of the options for you to structure your code is to group classes in modules by layers.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:26,000 --> 00:11:30,000
|
| 603 |
+
You can think about your application from architectural layer standpoint.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:30,000 --> 00:11:37,000
|
| 607 |
+
For example, you can have UI layer the network, layer the database layer services layer and model.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:37,000 --> 00:11:43,000
|
| 611 |
+
That group encode by layer is typically the default approach because after all, that's what the book's
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:43,000 --> 00:11:46,000
|
| 615 |
+
tutorials and framework samples tell us to do.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:47,000 --> 00:11:53,000
|
| 619 |
+
Here we organize in code by grouping things of the same type generally where the architecture considered
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:53,000 --> 00:11:54,000
|
| 623 |
+
to be a good thing.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:54,000 --> 00:12:01,000
|
| 627 |
+
Engineers useless to group their classes by applying separation of concerns, principle in this case
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:01,000 --> 00:12:05,000
|
| 631 |
+
less as a primary organisational mechanism for our code.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:05,000 --> 00:12:10,000
|
| 635 |
+
It comes with such advantages as it is simple and easy for understanding.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:10,000 --> 00:12:12,000
|
| 639 |
+
You want to change that access mechanism?
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:12,000 --> 00:12:14,000
|
| 643 |
+
Absolutely no problems.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:14,000 --> 00:12:15,000
|
| 647 |
+
Hammerson is in one place.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:16,000 --> 00:12:20,000
|
| 651 |
+
Testing of each layer in isolation from another layer is simpler.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:20,000 --> 00:12:25,000
|
| 655 |
+
But such approach also has some drawbacks, usually with such approach.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:25,000 --> 00:12:30,000
|
| 659 |
+
Cohesion inside each module is low and the coupling between items is very high.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:30,000 --> 00:12:33,000
|
| 663 |
+
This sounds like completely opposite of what we want to achieve.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:34,000 --> 00:12:39,000
|
| 667 |
+
At the same time, there is a community that is agree with separation of concerns of presentation,
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:39,000 --> 00:12:44,000
|
| 671 |
+
application, the main infrastructure, and agree it makes sense.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:44,000 --> 00:12:45,000
|
| 675 |
+
On the example.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:45,000 --> 00:12:51,000
|
| 679 |
+
You can see that each feature has its implementation spread out over multiple directories, over so-called
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:51,000 --> 00:12:53,000
|
| 683 |
+
implementation categories.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:53,000 --> 00:13:00,000
|
| 687 |
+
For example, you can see that all the feature items like all of you or the service or the wrapper are
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:00,000 --> 00:13:02,000
|
| 691 |
+
spread out into three different components.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:03,000 --> 00:13:08,000
|
| 695 |
+
Each directory contains items that usually are not closely related to each other.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:08,000 --> 00:13:14,000
|
| 699 |
+
In this example, Additon of Order feature involves code changes in different directories and software
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:14,000 --> 00:13:14,000
|
| 703 |
+
modules.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:15,000 --> 00:13:19,000
|
| 707 |
+
Also, deleting a feature can be performed as a single operation.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:19,000 --> 00:13:22,000
|
| 711 |
+
You have to attentively analyze each module.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:22,000 --> 00:13:27,000
|
| 715 |
+
Another popular approach to group classes is package by feature approach.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:27,000 --> 00:13:30,000
|
| 719 |
+
We might want to use this approach to reflect the feature set.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:31,000 --> 00:13:36,000
|
| 723 |
+
According to this principle, we need to place all items related to a single feature into a single module.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:37,000 --> 00:13:43,000
|
| 727 |
+
Following this approach, we can achieve high cohesion and high modularity at the same time, with low
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:43,000 --> 00:13:49,000
|
| 731 |
+
coupling between components classes at work together, I placed next to each other instead of being
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:49,000 --> 00:13:51,000
|
| 735 |
+
spread out all over the application.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:52,000 --> 00:13:57,000
|
| 739 |
+
In case you would like to disable or completely remove specific feature, you can just remove directory.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:58,000 --> 00:14:03,000
|
| 743 |
+
But to be able to apply this principle effectively, we need to answer one important question.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:04,000 --> 00:14:05,000
|
| 747 |
+
What is a feature?
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:05,000 --> 00:14:11,000
|
| 751 |
+
There is no strict definition of such term as feature and in real life feature understanding.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:11,000 --> 00:14:12,000
|
| 755 |
+
Vorys.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:12,000 --> 00:14:18,000
|
| 759 |
+
It could mean one specific use case was a whole set of operations related to a particular business concern.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:19,000 --> 00:14:25,000
|
| 763 |
+
With this approach, we have high cohesion and low carbon and the module level and above that we can
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:25,000 --> 00:14:29,000
|
| 767 |
+
easily to say what an application that's looking at its module structure.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:30,000 --> 00:14:35,000
|
| 771 |
+
On the other hand, in a typical Lares architecture, the cohesion inside the software module is usually
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:35,000 --> 00:14:42,000
|
| 775 |
+
low and the carbon emitting module is high for our services group and approach stage, that is very
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:42,000 --> 00:14:43,000
|
| 779 |
+
rare cases.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:43,000 --> 00:14:47,000
|
| 783 |
+
When we change technologies, we need to substitute the whole there completely.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:47,000 --> 00:14:54,000
|
| 787 |
+
Whereas new features are constantly added to the software, the package by feature concept does not
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:54,000 --> 00:14:58,000
|
| 791 |
+
imply that one module can never use items belonging to another one.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:58,000 --> 00:15:03,000
|
| 795 |
+
It will be properly to say that package by feature approach prefer a package prior to.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:03,000 --> 00:15:10,000
|
| 799 |
+
As the full scope and only increases the scope of an item to public when needed, package by feature
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:10,000 --> 00:15:14,000
|
| 803 |
+
has a lot of pros, not all of them are listed on this slide.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:14,000 --> 00:15:16,000
|
| 807 |
+
It also works dimensions and next benefits.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:17,000 --> 00:15:24,000
|
| 811 |
+
High modularity package by feature has more with high cohesion, high modularity and low carbon between
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:24,000 --> 00:15:27,000
|
| 815 |
+
models is a good navigation.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:27,000 --> 00:15:33,000
|
| 819 |
+
Software engineers need to do less searching for items since everything related to the change request
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:33,000 --> 00:15:37,000
|
| 823 |
+
Autoblog fix is placed in the same directory.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:37,000 --> 00:15:39,000
|
| 827 |
+
Better growth potential.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:39,000 --> 00:15:42,000
|
| 831 |
+
One component becomes way too large.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:42,000 --> 00:15:47,000
|
| 835 |
+
It can be refactored and be split into two separate modules in a natural way.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:47,000 --> 00:15:54,000
|
| 839 |
+
In case your hair package bilayer approach, you have comparatively monolithic module structure because
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:54,000 --> 00:15:59,000
|
| 843 |
+
as an application will grow in size, the number of layers will remain the same, but the amount of
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:59,000 --> 00:16:01,000
|
| 847 |
+
features will be increased.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:01,000 --> 00:16:06,000
|
| 851 |
+
Thus amount of classes in each module will increase without any bound.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:06,000 --> 00:16:11,000
|
| 855 |
+
But package by feature also comes with the price of its drawbacks.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:11,000 --> 00:16:15,000
|
| 859 |
+
Some of them are unspecified feature size.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:15,000 --> 00:16:19,000
|
| 863 |
+
In my opinion, this is the most critical disadvantage of packaging by feature.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:19,000 --> 00:16:25,000
|
| 867 |
+
First of all, because in real life, separation by features sometimes might look not so obvious as
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:25,000 --> 00:16:26,000
|
| 871 |
+
it is expected.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:27,000 --> 00:16:32,000
|
| 875 |
+
If you have log in feature of your current feature, everything is straight and clear here.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:32,000 --> 00:16:38,000
|
| 879 |
+
But what if you would have service which calculates distance from point A to point B and you need to
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:38,000 --> 00:16:44,000
|
| 883 |
+
perform these calculations in order feature and interactively delivery online feature, you will end
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:44,000 --> 00:16:50,000
|
| 887 |
+
up having components which are still needed to be shared and least of components which can be used in
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:50,000 --> 00:16:51,000
|
| 891 |
+
different features.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:51,000 --> 00:16:56,000
|
| 895 |
+
This is something with extremely hard to predict at the beginning and what you don't know, and the
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:56,000 --> 00:17:00,000
|
| 899 |
+
model with shared items has a risk to becomes a huge one.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:00,000 --> 00:17:06,000
|
| 903 |
+
Mezzanines potential in a tangible domain where everything is connected to everything.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:06,000 --> 00:17:10,000
|
| 907 |
+
Separation of modules into the future might become artificial.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:11,000 --> 00:17:14,000
|
| 911 |
+
Just remember that there is no silver bullet.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:14,000 --> 00:17:19,000
|
| 915 |
+
You should be aware of different approaches and practices and choose the one which works the best for
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:19,000 --> 00:17:21,000
|
| 919 |
+
your specific case and project.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:22,000 --> 00:17:25,000
|
| 923 |
+
Probably in real life, you don't need even to choose.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:25,000 --> 00:17:27,000
|
| 927 |
+
One of the two approaches suggest it.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:27,000 --> 00:17:32,000
|
| 931 |
+
Most likely it will be a combination of these two approaches where you will separate yourself to modules
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:32,000 --> 00:17:35,000
|
| 935 |
+
by layers and still will separate it by features inside.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:36,000 --> 00:17:41,000
|
| 939 |
+
There is also another factor that may impact our cost structure and that we can't underestimate.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:42,000 --> 00:17:49,000
|
| 943 |
+
On nineteen sixty eight, when Conway submitted an article to the major magazine at the time, didn't
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:17:49,000 --> 00:17:57,000
|
| 947 |
+
mention that a mention published his article with the tax head on how the committees in went after that.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:17:57,000 --> 00:18:03,000
|
| 951 |
+
Fred Brooks, in his famous book The Mythical Man Month, sided words of Kahnawake and called it Conaway's
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:03,000 --> 00:18:04,000
|
| 955 |
+
law.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:04,000 --> 00:18:11,000
|
| 959 |
+
The law sounds like this organizations which design systems are constrained to produce designs, which
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:11,000 --> 00:18:14,000
|
| 963 |
+
are copies of the communication structures of these organizations.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:15,000 --> 00:18:21,000
|
| 967 |
+
Even though Conaway's law not a scientific law and doesn't have mathematical proof, it was recognized
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:21,000 --> 00:18:24,000
|
| 971 |
+
by community as valid preposition from many environments.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:24,000 --> 00:18:30,000
|
| 975 |
+
Probably you already had a chance to see how this law affects in our projects and other projects where
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:30,000 --> 00:18:36,000
|
| 979 |
+
a group of people distributed teams combined, according to different rules, develop software together.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:36,000 --> 00:18:42,000
|
| 983 |
+
Honest law was not intended as a joke, but as a valid sociological observation.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:42,000 --> 00:18:49,000
|
| 987 |
+
It is a consequence of the fact that two software modules, A and B, can't interact correctly with
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:18:49,000 --> 00:18:55,000
|
| 991 |
+
each other unless the designer and implementer of a module communicates with the design and implementation
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:18:55,000 --> 00:18:56,000
|
| 995 |
+
of B module.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:18:57,000 --> 00:19:03,000
|
| 999 |
+
Thus, the interface structure of a software system necessarily will show a Congress with the social
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:03,000 --> 00:19:05,000
|
| 1003 |
+
structure of the organization that produced it.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:06,000 --> 00:19:10,000
|
| 1007 |
+
The initial thought architectural design, in most cases, not the best possible.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:11,000 --> 00:19:16,000
|
| 1011 |
+
We are dealing with software development where a lot of things can be extremely hard to predict until
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:16,000 --> 00:19:19,000
|
| 1015 |
+
the detailed plan and implementation.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:19,000 --> 00:19:23,000
|
| 1019 |
+
That's why initial software architecture design may need to change.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:23,000 --> 00:19:28,000
|
| 1023 |
+
Thus, effective design depends on how flexible organization is.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:28,000 --> 00:19:33,000
|
| 1027 |
+
Nowadays, there is a trend to build cross-functional and multidisciplinary teams.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:34,000 --> 00:19:39,000
|
| 1031 |
+
Such teams consist of people with different roles, different domain knowledge, guided by the business
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:39,000 --> 00:19:40,000
|
| 1035 |
+
capabilities.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:19:40,000 --> 00:19:47,000
|
| 1039 |
+
Cross-functional team can address any new requirement or new business definition from the start to end.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:19:47,000 --> 00:19:54,000
|
| 1043 |
+
This avoids processes overhead and produces different and often more distributed architecture with greater
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:19:54,000 --> 00:19:55,000
|
| 1047 |
+
capacity to evolve.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:19:56,000 --> 00:20:01,000
|
| 1051 |
+
The interesting thing to mention here is the connection between Conway's law and single responsibility
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:01,000 --> 00:20:01,000
|
| 1055 |
+
principle.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:02,000 --> 00:20:08,000
|
| 1059 |
+
The delivery of the software project, we can have multiple key stakeholders who has the biggest power
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:08,000 --> 00:20:14,000
|
| 1063 |
+
and the most interest in the goals of the project and each key stakeholder is empowered to submit is
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:14,000 --> 00:20:19,000
|
| 1067 |
+
a change request when you business requirement, which delivery teams should be able to address.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:19,000 --> 00:20:25,000
|
| 1071 |
+
So we can say that each delivery team, which is connected with key stakeholders, has a single responsibility
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:25,000 --> 00:20:29,000
|
| 1075 |
+
connected with a specific part of the requirements for the whole system.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:30,000 --> 00:20:36,000
|
| 1079 |
+
That's why a system architecture is designed in the way that each delivery team doesn't impact another
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:36,000 --> 00:20:36,000
|
| 1083 |
+
one.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:37,000 --> 00:20:42,000
|
| 1087 |
+
But in this case, we can treat single responsibility principle on another level of abstraction.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:42,000 --> 00:20:46,000
|
| 1091 |
+
In comparison, when we talk about this principle in scope of one class.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:47,000 --> 00:20:53,000
|
| 1095 |
+
So you can see on this simple example, we discussed how single responsibility, principle and Conaway's
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:53,000 --> 00:21:00,000
|
| 1099 |
+
law both affect our system architecture and called organization unions are grouping items in your application.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:00,000 --> 00:21:04,000
|
| 1103 |
+
You also need to take into consideration some technical factors.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:04,000 --> 00:21:10,000
|
| 1107 |
+
For example, in Java, if you smart and build two from a page, you're forced to follow some basic
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:10,000 --> 00:21:16,000
|
| 1111 |
+
conventions where to put source code, where to put the public resources and where to put resources,
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:21:16,000 --> 00:21:19,000
|
| 1115 |
+
which you don't want to be accessible from the outside of the server.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:21:19,000 --> 00:21:25,000
|
| 1119 |
+
Some of frameworks work better with a given structure like spring, and we see, for example, you can
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:21:25,000 --> 00:21:26,000
|
| 1123 |
+
group all your classes.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:21:26,000 --> 00:21:32,000
|
| 1127 |
+
We should process requests and that one package because this framework will scan specific package to
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:21:32,000 --> 00:21:34,000
|
| 1131 |
+
instantiate necessary request handlers.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:21:35,000 --> 00:21:37,000
|
| 1135 |
+
There is no harm in this technical factors.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:37,000 --> 00:21:43,000
|
| 1139 |
+
At the end of the day, software development process is always a question of tradeoffs between many
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:43,000 --> 00:21:43,000
|
| 1143 |
+
things.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:21:43,000 --> 00:21:47,000
|
| 1147 |
+
You can try to address one potential issue and receive another one.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:21:47,000 --> 00:21:48,000
|
| 1151 |
+
Not in the theory.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:21:49,000 --> 00:21:54,000
|
| 1155 |
+
You can always analyze specific case impartially and opt for the best option, which works specifically
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:21:54,000 --> 00:21:59,000
|
| 1159 |
+
for you and specifically for your project at this moment of time.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:21:59,000 --> 00:22:05,000
|
| 1163 |
+
We shouldn't forget the tools and practices which were described in this lesson weren't created to make
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:22:05,000 --> 00:22:06,000
|
| 1167 |
+
things even more complex.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:22:06,000 --> 00:22:11,000
|
| 1171 |
+
The goal is one to simplify solution of most common issues.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:22:11,000 --> 00:22:13,000
|
| 1175 |
+
That's where partners are come from all.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:22:13,000 --> 00:22:19,000
|
| 1179 |
+
Always remember that your structure should be easily navigable and should embrace the most common scenarios.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:22:20,000 --> 00:22:21,000
|
| 1183 |
+
It also works dimensions.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:22:21,000 --> 00:22:26,000
|
| 1187 |
+
That's probably the one of the proven ways to learn how to architect system so that it would be scalable,
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:22:27,000 --> 00:22:32,000
|
| 1191 |
+
maintainable and elements of the system will be easily reusable is getting more experience.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:22:33,000 --> 00:22:35,000
|
| 1195 |
+
Feel free to find inspiration in open source projects.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:22:36,000 --> 00:22:42,000
|
| 1199 |
+
Experiment with your own projects to find the recipe which will work and never forget about naming conventions
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:22:42,000 --> 00:22:43,000
|
| 1203 |
+
in your code.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:22:44,000 --> 00:22:50,000
|
| 1207 |
+
No matter your given name to a variable across an interface or a module clean code design.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:22:50,000 --> 00:22:54,000
|
| 1211 |
+
It is a constant process, but not one time activity.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:22:54,000 --> 00:22:59,000
|
| 1215 |
+
Use tools which we have in place to support in design and to share experience with team members.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:23:00,000 --> 00:23:05,000
|
| 1219 |
+
For example, you can drive clean design on your projects through the code review process or pair programming.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:23:06,000 --> 00:23:11,000
|
| 1223 |
+
Nowadays we have multiple tools for study code analysis, which might help you to analyze metrics which
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:23:11,000 --> 00:23:14,000
|
| 1227 |
+
will force to maintain the architecture of your application.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:23:15,000 --> 00:23:21,000
|
| 1231 |
+
For example, the next tools check JQ Assistant Tool, which can help you to validate dependencies between
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:23:21,000 --> 00:23:27,000
|
| 1235 |
+
more use of your project, including detection of common problems like cyclic dependencies.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:23:27,000 --> 00:23:29,000
|
| 1239 |
+
It is also forces naming convention.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:23:30,000 --> 00:23:36,000
|
| 1243 |
+
Such tool can easily be plugged into the build process to automate detection of constraint violations
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:23:36,000 --> 00:23:41,000
|
| 1247 |
+
and generate reports about user defined concepts and metrics structure.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:23:41,000 --> 00:23:48,000
|
| 1251 |
+
Rieser software like this one has one goal to allow software developers to easily create software architecture
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:23:48,000 --> 00:23:50,000
|
| 1255 |
+
diagrams that reflect the code.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:23:51,000 --> 00:23:56,000
|
| 1259 |
+
Unfortunately, static diagrams whether drawn on board what was the general purpose diagram?
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:23:56,000 --> 00:24:02,000
|
| 1263 |
+
And to tend to get out of date quickly and often don't reflect the real structure of the code.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:24:03,000 --> 00:24:06,000
|
| 1267 |
+
That's where software like structure structuralism come into play.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:24:06,000 --> 00:24:09,000
|
| 1271 |
+
I believe that you can find a lot of other similar tools.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:24:10,000 --> 00:24:14,000
|
| 1275 |
+
These are just a few that I'd like to specify as a reference.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:24:15,000 --> 00:24:16,000
|
| 1279 |
+
That's what I have for you for today.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:24:17,000 --> 00:24:19,000
|
| 1283 |
+
Let's recap what we have learned today.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:24:19,000 --> 00:24:20,000
|
| 1287 |
+
In this lesson.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:24:20,000 --> 00:24:27,000
|
| 1291 |
+
We learned what captain principles are, and we talked in detail about such principles as cyclic dependencies,
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:24:27,000 --> 00:24:30,000
|
| 1295 |
+
stable dependencies and stable abstractions.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:24:30,000 --> 00:24:34,000
|
| 1299 |
+
We also reviewed with your other principles that can impact your architecture.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:24:34,000 --> 00:24:40,000
|
| 1303 |
+
Now you know how to group your code and package by way of principle and package by feature.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:24:40,000 --> 00:24:46,000
|
| 1307 |
+
Principal explained you Conaway's law and how technical factors may impact our, quote, organization.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:24:47,000 --> 00:24:47,000
|
| 1311 |
+
That's it.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:24:48,000 --> 00:24:49,000
|
| 1315 |
+
Thanks a lot for your attention.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:24:49,000 --> 00:24:52,000
|
| 1319 |
+
Have a great day and see you in the next lesson.
|
| 1320 |
+
|
38 - Object-oriented Architecture, Clean Code Design (Advanced)/external-links.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
002 Source-code-of-Tell-don-t-ask-example-
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/telldontask
|
| 4 |
+
|
| 5 |
+
002 Source-code-of-data-structures-example
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/datastructures
|
| 7 |
+
|
| 8 |
+
004 Source-code-examples-shown-in-the-lesson
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/kiss
|
| 10 |
+
|
| 11 |
+
005 Source-code-examples-shown-in-the-lesson
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/yagni
|
| 13 |
+
|
| 14 |
+
007 Source-code-examples-shown-in-the-lesson
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/dry
|
39 - GoF Design Patterns of Software Architecture in OOP/001 GoF Patterns Overview_en.srt
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:09,000
|
| 3 |
+
How are the students today with that very important topic?
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:09,000 --> 00:00:15,000
|
| 7 |
+
We start learning of so-called Gulfport's in object oriented design, and even before we start learning
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:15,000 --> 00:00:20,000
|
| 11 |
+
of golf partners, we'll try to answer a simple question why do we need design patterns?
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:21,000 --> 00:00:26,000
|
| 15 |
+
And the context will help you to feel motivation that stands behind each partner.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:26,000 --> 00:00:31,000
|
| 19 |
+
In this lesson, we are going to answer first one golf patterns are and why they're called.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:31,000 --> 00:00:38,000
|
| 23 |
+
So after that, we'll learn what the key points of golf patterns we are going to review with your occasional
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:38,000 --> 00:00:45,000
|
| 27 |
+
structural and behavioral patterns, how to explain what is the difference between these types of patterns.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:45,000 --> 00:00:48,000
|
| 31 |
+
And I will list main patterns from each group.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:52,000
|
| 35 |
+
Also, we will learn what class and object patterns are.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:52,000 --> 00:00:58,000
|
| 39 |
+
This lesson will help you to understand what we are going to learn in this section, namely what partners
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:58,000 --> 00:00:59,000
|
| 43 |
+
will learn.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:00,000 --> 00:01:05,000
|
| 47 |
+
And at the end of the lesson, I will give answers on the most common questions of my students who just
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:05,000 --> 00:01:07,000
|
| 51 |
+
started going in design patterns.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:08,000 --> 00:01:10,000
|
| 55 |
+
It looks like we have really a lot of things to learn today.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:10,000 --> 00:01:11,000
|
| 59 |
+
Let's start.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:11,000 --> 00:01:14,000
|
| 63 |
+
And as I said before, let's try to understand first.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:21,000
|
| 67 |
+
Why do we need design patterns when we develop software the way how we think is different?
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:21,000 --> 00:01:25,000
|
| 71 |
+
Each of us can come up with different solutions for the same engineering issue.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:26,000 --> 00:01:32,000
|
| 75 |
+
And back that time, there was no any standard or general advisees of how to design application.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:33,000 --> 00:01:38,000
|
| 79 |
+
Each project had new style, new structure, and each new team members are joining.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:38,000 --> 00:01:41,000
|
| 83 |
+
The team brought his own vision on architecture.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:41,000 --> 00:01:45,000
|
| 87 |
+
Understanding of project architecture was a very complex task.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:45,000 --> 00:01:51,000
|
| 91 |
+
Well, design partners address these kind of issues and provide us with a set of solutions for most
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:51,000 --> 00:01:52,000
|
| 95 |
+
difficult problems.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:52,000 --> 00:01:56,000
|
| 99 |
+
And these solutions serve as a platform for all developers.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:57,000 --> 00:02:01,000
|
| 103 |
+
We also can treat partners as recorded experience of experts in the field.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:02,000 --> 00:02:08,000
|
| 107 |
+
These design partners are intended to be used in object oriented programs and allows us to use the same
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:08,000 --> 00:02:10,000
|
| 111 |
+
partners across different projects.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:10,000 --> 00:02:16,000
|
| 115 |
+
Now we understand the context, and I believe it is clear for you why we need to follow design partners
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:16,000 --> 00:02:17,000
|
| 119 |
+
during the development.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:17,000 --> 00:02:24,000
|
| 123 |
+
But probably the interesting thing is to understand why these partners called Gulf Partners.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:25,000 --> 00:02:31,000
|
| 127 |
+
The name comes from the group of authors of the one great book that was written in 1990 Force.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:32,000 --> 00:02:38,000
|
| 131 |
+
The book was written by Eric Gummo, Richard Helm, Robert Johnson and John say this.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:38,000 --> 00:02:40,000
|
| 135 |
+
You can find this book online if you wish.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:40,000 --> 00:02:45,000
|
| 139 |
+
The book name is Design Patterns, elements of reusable object oriented software.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:46,000 --> 00:02:48,000
|
| 143 |
+
As I said, you can find and download it.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:48,000 --> 00:02:54,000
|
| 147 |
+
But anyway, in this course I will walk you through the most popular patterns that are still relevant
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:54,000 --> 00:02:55,000
|
| 151 |
+
even nowadays.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:56,000 --> 00:03:01,000
|
| 155 |
+
And I will explain these patterns in simple words with the help of real life examples that I prepared
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:01,000 --> 00:03:04,000
|
| 159 |
+
for you and that are true examples from my practice.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:05,000 --> 00:03:13,000
|
| 163 |
+
This also became known as Gang of Four, and basically partners from that book is called Gulf Partners.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:13,000 --> 00:03:19,000
|
| 167 |
+
Even despite Baja's I described in the book with examples, there may be different models, variations
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:19,000 --> 00:03:22,000
|
| 171 |
+
of such patterns, and I will show you all of them.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:23,000 --> 00:03:29,000
|
| 175 |
+
Gang of Four described one in three portraits that were developed by the common experiences of software
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:29,000 --> 00:03:31,000
|
| 179 |
+
developers of a period of time.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:31,000 --> 00:03:33,000
|
| 183 |
+
Nowadays, it is pretty common practice.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:33,000 --> 00:03:39,000
|
| 187 |
+
When a new member joins a development team, then the developer learns about the existing architecture.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:40,000 --> 00:03:45,000
|
| 191 |
+
This allows the developer to actively participate in the development process within a short period of
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:45,000 --> 00:03:46,000
|
| 195 |
+
time.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:46,000 --> 00:03:52,000
|
| 199 |
+
What else we need to know about growth patterns before jump into details, let's review key points of
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:52,000 --> 00:03:53,000
|
| 203 |
+
growth patterns.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:54,000 --> 00:03:56,000
|
| 207 |
+
The following are key points about design patterns.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:57,000 --> 00:04:03,000
|
| 211 |
+
Each design pattern is a general and reusable solution for repeatable and commonly occurring issues.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:03,000 --> 00:04:10,000
|
| 215 |
+
So the concept tells us that in typical issues you can apply typical solution without reinventing the
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:10,000 --> 00:04:10,000
|
| 219 |
+
wheel.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:11,000 --> 00:04:14,000
|
| 223 |
+
And these solutions have approval over long periods of time.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:14,000 --> 00:04:20,000
|
| 227 |
+
As you can understand from this point, there are no reasons to follow patterns just because it is a
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:20,000 --> 00:04:27,000
|
| 231 |
+
common practice we follow just to solve our specific issue, which is whose experience it was collected
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:27,000 --> 00:04:28,000
|
| 235 |
+
over time.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:29,000 --> 00:04:35,000
|
| 239 |
+
Usually each pattern is a template of our solution that help us to achieve that better architecture
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:35,000 --> 00:04:35,000
|
| 243 |
+
design.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:35,000 --> 00:04:40,000
|
| 247 |
+
Significantly faster patterns are generic and flexible for customization.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:40,000 --> 00:04:45,000
|
| 251 |
+
So each pattern describes the way how to create objects and classes.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:45,000 --> 00:04:52,000
|
| 255 |
+
And also the pattern provides us with the description of customization, the solution to achieve goal
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:52,000 --> 00:04:53,000
|
| 259 |
+
in the particular context.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:54,000 --> 00:04:57,000
|
| 263 |
+
Zwigoff patterns describe twenty three design patterns.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:57,000 --> 00:05:02,000
|
| 267 |
+
Each of these patterns focuses on a particular object oriented design issue.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:02,000 --> 00:05:09,000
|
| 271 |
+
To solve, each partner can also describe the consequences and tradeoffs of use, all these 23 questions
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:09,000 --> 00:05:17,000
|
| 275 |
+
are grouped in three main groups, Ziya creation patterns, structural and behavioral patterns.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:17,000 --> 00:05:20,000
|
| 279 |
+
Let's look at the list of patterns from each group.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:20,000 --> 00:05:21,000
|
| 283 |
+
In this course.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:21,000 --> 00:05:24,000
|
| 287 |
+
We are going to learn patterns from the list on this slide.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:24,000 --> 00:05:27,000
|
| 291 |
+
We don't have goal to halt overview of each part.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:27,000 --> 00:05:32,000
|
| 295 |
+
And I just want to give you an overview of what we are going to learn with you in this course.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:33,000 --> 00:05:37,000
|
| 299 |
+
You can see the names of all twenty three partners that are grouped into three groups.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:38,000 --> 00:05:46,000
|
| 303 |
+
So you can see that such patterns as Singleton prototype factory, MassArt builder and factory partners
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:46,000 --> 00:05:48,000
|
| 307 |
+
are considered to be a creation of bias.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:49,000 --> 00:05:51,000
|
| 311 |
+
What is the main goal of Gradational partners?
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:51,000 --> 00:05:54,000
|
| 315 |
+
These partners describe the instantiation process.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:55,000 --> 00:06:02,000
|
| 319 |
+
You make the system independent from how the objects are composed, created and represented in software
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:02,000 --> 00:06:03,000
|
| 323 |
+
engineering creation.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:03,000 --> 00:06:09,000
|
| 327 |
+
Design patterns are design partners and deal with object creation mechanism, trying to create objects
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:09,000 --> 00:06:12,000
|
| 331 |
+
in a manner suitable to the situation.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:12,000 --> 00:06:19,000
|
| 335 |
+
The basic form of object creation could result in design problems or added complexity to the design
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:20,000 --> 00:06:25,000
|
| 339 |
+
creation design part and solve this problem by somehow controlling this object creation.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:25,000 --> 00:06:33,000
|
| 343 |
+
Sometimes creation of patterns are competitors there cases one is a prototype or abstract factory could
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:33,000 --> 00:06:34,000
|
| 347 |
+
be used profitably.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:34,000 --> 00:06:37,000
|
| 351 |
+
At other times they are complementary.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:37,000 --> 00:06:43,000
|
| 355 |
+
Abasic factory might store a set of prototypes from which to clone and return product objects.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:43,000 --> 00:06:50,000
|
| 359 |
+
Abstract factory might store a set of prototypes from which to clone and return a group of related objects.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:50,000 --> 00:06:55,000
|
| 363 |
+
Builder can use one of the other parts to implement which components get built.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:56,000 --> 00:07:01,000
|
| 367 |
+
Abstract factory builder and prototype can use Singleton in the implementation.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:02,000 --> 00:07:08,000
|
| 371 |
+
Abstract factory classes are often implemented with factory methods, but they can also be implemented
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:08,000 --> 00:07:09,000
|
| 375 |
+
using prototype.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:10,000 --> 00:07:14,000
|
| 379 |
+
Builder focuses on constructing a complex object step by step.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:15,000 --> 00:07:21,000
|
| 383 |
+
Often design stars out using factory method, which is less complicated, more customizable based on
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:21,000 --> 00:07:28,000
|
| 387 |
+
subclasses, and evolve towards abstract factory prototype or builder that is more flexible and a more
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:28,000 --> 00:07:33,000
|
| 391 |
+
complex solution as a design and discovers where more flexibility is needed.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:34,000 --> 00:07:36,000
|
| 395 |
+
The next group is a group of structural patterns.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:37,000 --> 00:07:45,000
|
| 399 |
+
Their proxy pardon flyweight Partan Composite Partan Bridge Facade Decorator and Adapter Partan.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:45,000 --> 00:07:53,000
|
| 403 |
+
This group of partners focuses on how classes and objects can be composed to form relatively large structures.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:53,000 --> 00:07:57,000
|
| 407 |
+
They generally use inheritance to compose interfaces or implementations.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:58,000 --> 00:07:59,000
|
| 411 |
+
Structural design partners.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:59,000 --> 00:08:00,000
|
| 415 |
+
I design patterns.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:00,000 --> 00:08:06,000
|
| 419 |
+
That is a design by identifying a simple way to realize the relationships between entities.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:06,000 --> 00:08:10,000
|
| 423 |
+
What defines and manner for creating relationships between objects?
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:10,000 --> 00:08:13,000
|
| 427 |
+
What is the difference between structural and relational parents?
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:14,000 --> 00:08:19,000
|
| 431 |
+
Conditional patterns are patterns that provides a way to create objects while height in the creation
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:19,000 --> 00:08:20,000
|
| 435 |
+
of logic.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:20,000 --> 00:08:26,000
|
| 439 |
+
This provides us flexibility for creating objects based on different use cases.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:26,000 --> 00:08:29,000
|
| 443 |
+
Some examples of operational patterns we have discussed already.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:29,000 --> 00:08:33,000
|
| 447 |
+
So based on your use case, you can decide which point to use.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:33,000 --> 00:08:40,000
|
| 451 |
+
On the other hand, structural patterns provide us with options how to clap classes and objects together
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:40,000 --> 00:08:42,000
|
| 455 |
+
to form large structures.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:42,000 --> 00:08:43,000
|
| 459 |
+
Does it make sense?
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:43,000 --> 00:08:46,000
|
| 463 |
+
And we have group of behavioral patterns here on the slide.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:47,000 --> 00:08:48,000
|
| 467 |
+
These as an experience.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:49,000 --> 00:08:59,000
|
| 471 |
+
Observe Observer Strategy Template Masset Command Iterator Mylanta, state mediator, chain of responsibility,
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:59,000 --> 00:09:01,000
|
| 475 |
+
visitor, partner and interpreter.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:01,000 --> 00:09:02,000
|
| 479 |
+
Pratham.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:02,000 --> 00:09:09,000
|
| 483 |
+
These points put a stress on algorithm's and the assignment of responsibilities and objects to ensure
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:09,000 --> 00:09:11,000
|
| 487 |
+
efficient communication between them.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:12,000 --> 00:09:16,000
|
| 491 |
+
Behavioral patterns explain how objects interact between each other.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:16,000 --> 00:09:23,000
|
| 495 |
+
These partners describe how different objects and classes send messages to each other to make things
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:23,000 --> 00:09:27,000
|
| 499 |
+
happen and how the steps of a task are divided among different objects.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:28,000 --> 00:09:31,000
|
| 503 |
+
What is the difference between creation and structural patterns?
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:32,000 --> 00:09:38,000
|
| 507 |
+
Congressional partners mostly describe a moment of time, moment of object creation and structural patterns
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:38,000 --> 00:09:41,000
|
| 511 |
+
describe and more or less static structure.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:41,000 --> 00:09:44,000
|
| 515 |
+
Behavioral patterns describe a process or a flow.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:45,000 --> 00:09:51,000
|
| 519 |
+
Behavioral patterns, on the other hand, changes the way your classes behave by changing the way they
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:51,000 --> 00:09:57,000
|
| 523 |
+
interact with other classes and interfaces and the way other classes and interfaces interact with them.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:58,000 --> 00:10:02,000
|
| 527 |
+
Now, you know the main classification of Goave patterns these.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:02,000 --> 00:10:07,000
|
| 531 |
+
Apartments that we are going to learn, but also there is another classification of old patterns that
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:07,000 --> 00:10:14,000
|
| 535 |
+
we need to be aware of, the Gang of Four made another classification based on Skoch Lane was a department
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:14,000 --> 00:10:22,000
|
| 539 |
+
primary, focuses on the colossus or its objects class deal with classes and subclasses.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:22,000 --> 00:10:30,000
|
| 543 |
+
They use inheritance mechanism which are static and fixed at compile time object pathogen's view with
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:30,000 --> 00:10:32,000
|
| 547 |
+
objects that can change at runtime.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:33,000 --> 00:10:36,000
|
| 551 |
+
So objects patterns are dynamic because.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:36,000 --> 00:10:42,000
|
| 555 |
+
We used to investigate the current slide and believes there is no need to name out loud each person
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:42,000 --> 00:10:43,000
|
| 559 |
+
in each group here.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:43,000 --> 00:10:49,000
|
| 563 |
+
This table will help you to understand what design patterns in which group consider it to be is a class
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:49,000 --> 00:10:50,000
|
| 567 |
+
of objects.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:51,000 --> 00:10:55,000
|
| 571 |
+
Now let me answer the most popular questions from my students.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:55,000 --> 00:10:59,000
|
| 575 |
+
And the first question is related to the difference between lust and object patterns.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:00,000 --> 00:11:05,000
|
| 579 |
+
Namely, if this is the first time you see these spirals and trying to understand them.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:05,000 --> 00:11:11,000
|
| 583 |
+
The difference between these two groups is not obvious from the first glance, angry answering this
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:11,000 --> 00:11:13,000
|
| 587 |
+
question in a general way.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:13,000 --> 00:11:17,000
|
| 591 |
+
Class patterns focus on static relationship and objects.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:17,000 --> 00:11:20,000
|
| 595 |
+
Parents can focus on dynamic relationships.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:20,000 --> 00:11:28,000
|
| 599 |
+
As the name suggests, class parents focus on classes and their subclasses and object patterns focus
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:28,000 --> 00:11:30,000
|
| 603 |
+
on the objects relationships.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:30,000 --> 00:11:34,000
|
| 607 |
+
On this slide, they can see specific difference between class and object patterns.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:35,000 --> 00:11:40,000
|
| 611 |
+
When we are talking about correlational patterns, we should understand that class patterns will be
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:40,000 --> 00:11:44,000
|
| 615 |
+
based on the inheritance and mechanisms that are fixed and compile time.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:45,000 --> 00:11:52,000
|
| 619 |
+
Class patterns can differ creation of object to subclasses, whereas object patterns use objects at
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:52,000 --> 00:11:55,000
|
| 623 |
+
the wrong time and can delegate object creation to another object.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:56,000 --> 00:11:57,000
|
| 627 |
+
As we go through each part.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:57,000 --> 00:12:00,000
|
| 631 |
+
And you will see this difference on real examples.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:00,000 --> 00:12:07,000
|
| 635 |
+
Structural class patterns focus on composition of classes, whereas structural objects patterns focus
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:07,000 --> 00:12:09,000
|
| 639 |
+
on different ways of objects composition.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:10,000 --> 00:12:16,000
|
| 643 |
+
The hero class patterns describe algorithms and execution flows and behavioral objects.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:16,000 --> 00:12:22,000
|
| 647 |
+
Patterns describe how different objects can work together and complete a task home.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:22,000 --> 00:12:23,000
|
| 651 |
+
This makes more sense.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:23,000 --> 00:12:27,000
|
| 655 |
+
Now, the next question that is also one of the popular ones.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:27,000 --> 00:12:32,000
|
| 659 |
+
It was apparent that we are going to learn aspecific to any of the programming language.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:33,000 --> 00:12:34,000
|
| 663 |
+
The short answer is no.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:35,000 --> 00:12:41,000
|
| 667 |
+
The patterns are general and can be reused in different programming languages where object oriented
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:41,000 --> 00:12:42,000
|
| 671 |
+
approach is applied.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:42,000 --> 00:12:47,000
|
| 675 |
+
Both partners are just templates that can be implemented in different programming languages.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:47,000 --> 00:12:54,000
|
| 679 |
+
Take into account specifics of any particular language is the next question is can implementation of
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:54,000 --> 00:12:58,000
|
| 683 |
+
one part in my code exclude the possibility of applying different parts?
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:59,000 --> 00:13:00,000
|
| 687 |
+
I would answer it this way.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:01,000 --> 00:13:04,000
|
| 691 |
+
In most cases, parents complement each other.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:04,000 --> 00:13:09,000
|
| 695 |
+
Some other persons have just subtle differences and even more.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:09,000 --> 00:13:13,000
|
| 699 |
+
Combining different patterns in one application is a common practice nowadays.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:14,000 --> 00:13:19,000
|
| 703 |
+
In the case you have any other questions at this moment, do not hesitate to leave your question in
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:19,000 --> 00:13:20,000
|
| 707 |
+
comments to this video.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:21,000 --> 00:13:23,000
|
| 711 |
+
Let's recap what we have learned today.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:24,000 --> 00:13:25,000
|
| 715 |
+
In this lesson we learned.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:25,000 --> 00:13:29,000
|
| 719 |
+
Why do we need design patterns and what growth patterns are explained?
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:29,000 --> 00:13:31,000
|
| 723 |
+
Key points of growth patterns.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:32,000 --> 00:13:37,000
|
| 727 |
+
Now, you know, what is the difference between correlational structural and behavioural group of parents?
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:38,000 --> 00:13:44,000
|
| 731 |
+
Also, we learned what class and object patterns are, and I answer it as the most common questions
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:44,000 --> 00:13:48,000
|
| 735 |
+
of my students about design patterns that set for this lesson.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:48,000 --> 00:13:50,000
|
| 739 |
+
Thanks a lot for your attention.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:50,000 --> 00:13:53,000
|
| 743 |
+
Have a great day and see you in the next lesson.
|
| 744 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/002 Creational Patterns_en.srt
ADDED
|
@@ -0,0 +1,1688 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:10,000
|
| 3 |
+
Hello there, students in this class, and we start learning correlational patterns in previous lessons,
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:15,000
|
| 7 |
+
we already performed an overview of correlational structural and behavioral patterns.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:15,000 --> 00:00:21,000
|
| 11 |
+
Now it is time to learn patterns from each group one by one, and we'll start from correlational patterns.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:21,000 --> 00:00:28,000
|
| 15 |
+
That's why in this lesson, we'll dive into the specifics of each gradational pattern in our plans to
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:28,000 --> 00:00:33,000
|
| 19 |
+
review today's single done prototype factor and method builder and abstract factory pattern.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:34,000 --> 00:00:39,000
|
| 23 |
+
Especially for this lesson, I prepared good examples that will help you to understand and learn these
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:39,000 --> 00:00:40,000
|
| 27 |
+
patterns faster.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:41,000 --> 00:00:47,000
|
| 31 |
+
Let's start in the first part on a Singleton will review each part in the similar format.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:47,000 --> 00:00:54,000
|
| 35 |
+
The first thing that we'll learn for each project is its intent and what problem we are going to address
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:54,000 --> 00:00:54,000
|
| 39 |
+
with the sporran.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:55,000 --> 00:01:02,000
|
| 43 |
+
Intent of the Singleton pattern is to ensure a class has only one instance and provide a global point
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:02,000 --> 00:01:03,000
|
| 47 |
+
of access to it.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:04,000 --> 00:01:09,000
|
| 51 |
+
But what problem will address in the case will have only one instance of object in our app.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:09,000 --> 00:01:16,000
|
| 55 |
+
In some cases, we don't need to create a new instance of the class each time we need immagine simple
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:16,000 --> 00:01:16,000
|
| 59 |
+
example.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:16,000 --> 00:01:19,000
|
| 63 |
+
You have type code order management service.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:19,000 --> 00:01:26,000
|
| 67 |
+
The object of this class can place order and you really don't need to create multiple objects of the
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:26,000 --> 00:01:28,000
|
| 71 |
+
same type because actually you don't need it.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:29,000 --> 00:01:32,000
|
| 75 |
+
What you need is just a behavior of place in order.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:32,000 --> 00:01:38,000
|
| 79 |
+
And this behavior can be executed by one single object in the application during the runtime.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:38,000 --> 00:01:45,000
|
| 83 |
+
We are going to save a little bit memory in a heap by not creating new object each new time we need
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:45,000 --> 00:01:45,000
|
| 87 |
+
it.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:45,000 --> 00:01:51,000
|
| 91 |
+
We know that Java has automated memory management and we can find garbage collector in Java too.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:51,000 --> 00:01:58,000
|
| 95 |
+
But in case we will create millions of such objects that we just use only one time and that's it, we
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:58,000 --> 00:02:03,000
|
| 99 |
+
will wake up garbage collector and this can reduce performance a little bit and temporarily.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:03,000 --> 00:02:09,000
|
| 103 |
+
So in this case, I just want to be sure that I don't need to make garbage collector work by creating
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:09,000 --> 00:02:11,000
|
| 107 |
+
a lot of object in memory.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:11,000 --> 00:02:17,000
|
| 111 |
+
Now, when we understood the goal of Singleton pardon, let's jump to the example and we'll look at
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:17,000 --> 00:02:18,000
|
| 115 |
+
the implementation.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:18,000 --> 00:02:21,000
|
| 119 |
+
So here we have order management, service class.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:21,000 --> 00:02:27,000
|
| 123 |
+
The first thing that we need to do if we want to implement Singleton pardon is to declare private static
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:27,000 --> 00:02:28,000
|
| 127 |
+
fields of the same type.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:29,000 --> 00:02:33,000
|
| 131 |
+
This field will hold the reference to the single instance of the type.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:33,000 --> 00:02:37,000
|
| 135 |
+
The second thing that we need to do is to create a private constructor.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:37,000 --> 00:02:43,000
|
| 139 |
+
We need to make constructor private so that no one will be able to get access to it and call this constructor
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:43,000 --> 00:02:45,000
|
| 143 |
+
outside of this class.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:45,000 --> 00:02:50,000
|
| 147 |
+
This allows us to restrict objects instantiation outside of this class.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:50,000 --> 00:02:54,000
|
| 151 |
+
The the things that we should do, we need to declare public static function.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:55,000 --> 00:03:01,000
|
| 155 |
+
We'll call it accessor function that will allow and users to access our object when it will be needed.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:02,000 --> 00:03:08,000
|
| 159 |
+
Pay attention to this function should be public and we will invoke it with the help of the class taking
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:08,000 --> 00:03:11,000
|
| 163 |
+
into account we won't be able to create an instance of a class.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:12,000 --> 00:03:16,000
|
| 167 |
+
Also, I will implement the initialization inside this accessor function.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:16,000 --> 00:03:18,000
|
| 171 |
+
What does the initialization mean?
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:19,000 --> 00:03:25,000
|
| 175 |
+
This means that I initialise object, not when the program is started, but I initialize the object
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:25,000 --> 00:03:32,000
|
| 179 |
+
on request when it is first called here in MassArt, you can see that I perform check and if our static
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:32,000 --> 00:03:36,000
|
| 183 |
+
field is now, then I initialise object.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:36,000 --> 00:03:43,000
|
| 187 |
+
In both cases I return the reference to the same object all times to avoid the very edge case of creation
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:43,000 --> 00:03:46,000
|
| 191 |
+
of two objects from different sets of execution.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:46,000 --> 00:03:52,000
|
| 195 |
+
I also add synchronized keyword to this method to make sure that only once relative execution will be
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:52,000 --> 00:03:54,000
|
| 199 |
+
able to enter this method.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:54,000 --> 00:04:00,000
|
| 203 |
+
But simultaneously and after that you can declare any non static behavior of this type.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:00,000 --> 00:04:04,000
|
| 207 |
+
So any message you would like to create, feel free to do it.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:04,000 --> 00:04:07,000
|
| 211 |
+
You will be able to call these methods on this object.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:07,000 --> 00:04:13,000
|
| 215 |
+
I will add one method placeholder, just an example here, basically.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:13,000 --> 00:04:18,000
|
| 219 |
+
That said, let me now open the file and show you how we can use Singleton Parren.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:18,000 --> 00:04:22,000
|
| 223 |
+
I am writing this file to explore console output with you.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:22,000 --> 00:04:27,000
|
| 227 |
+
I can create two references and initialize and use order management service object.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:28,000 --> 00:04:34,000
|
| 231 |
+
And when I compare it with equals operator, I get true because in both cases I get the reference to
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:34,000 --> 00:04:40,000
|
| 235 |
+
the same object and you can initialize any filter for the management service type in your program like
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:40,000 --> 00:04:41,000
|
| 239 |
+
this.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:41,000 --> 00:04:45,000
|
| 243 |
+
And be sure that you have only one object of the current type in the memory.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:46,000 --> 00:04:49,000
|
| 247 |
+
You can see here that taking into account our constructor is private.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:50,000 --> 00:04:57,000
|
| 251 |
+
I can't invoke constructor and once we get reference to object of our type, we can call any other methods
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:57,000 --> 00:04:58,000
|
| 255 |
+
of this object.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:58,000 --> 00:05:02,000
|
| 259 |
+
So here I can call place or a method, for example.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:02,000 --> 00:05:09,000
|
| 263 |
+
And we can see in console output that this message was invoked on the Object Hoglan, now it is clear
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:09,000 --> 00:05:11,000
|
| 267 |
+
for you how to implement Singleton pardon?
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:12,000 --> 00:05:13,000
|
| 271 |
+
Now let's discuss a few things.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:14,000 --> 00:05:20,000
|
| 275 |
+
It is worth to mention that sometimes you can find in the Internet that Singleton pardon is pure evil
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:20,000 --> 00:05:27,000
|
| 279 |
+
and somebody even treated as an antiabortion and telling us that is something we never should do.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:27,000 --> 00:05:31,000
|
| 283 |
+
I recommend you to be professional and don't fall in the false argument.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:32,000 --> 00:05:35,000
|
| 287 |
+
Let's try to understand why some people had some guilt on pardon.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:36,000 --> 00:05:40,000
|
| 291 |
+
First of all, I would like to say that in a case, this pardon would not be needed.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:40,000 --> 00:05:41,000
|
| 295 |
+
It would just don't exist.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:42,000 --> 00:05:43,000
|
| 299 |
+
But it exists for a reason.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:44,000 --> 00:05:49,000
|
| 303 |
+
So each pardon comes with pros and cons and we just should be aware about those rather.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:49,000 --> 00:05:54,000
|
| 307 |
+
And statements at this point is that each pardon is good for a specific case.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:54,000 --> 00:06:01,000
|
| 311 |
+
The first thing that haters of Singleton pardon is mentioning is that this specific implementation violates
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:01,000 --> 00:06:02,000
|
| 315 |
+
single responsibility principle.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:03,000 --> 00:06:09,000
|
| 319 |
+
So at this moment, our order management service is responsible for both managing his own life cycle
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:09,000 --> 00:06:11,000
|
| 323 |
+
and order management.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:11,000 --> 00:06:17,000
|
| 327 |
+
But how critical it is, I would say that taking into account his first responsibility, we have mentioned
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:17,000 --> 00:06:24,000
|
| 331 |
+
managing lifecycle doesn't depend on other units and it is very little chance that this responsibility
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:24,000 --> 00:06:26,000
|
| 335 |
+
becomes a separate reason to change.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:26,000 --> 00:06:33,000
|
| 339 |
+
And also, one will learn frameworks for Enterprise Java, for example, IGB that stands for Enterprise
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:33,000 --> 00:06:35,000
|
| 343 |
+
Java Beans Hotspring Framework.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:35,000 --> 00:06:41,000
|
| 347 |
+
We will discover that these technologies describe so-called containers that manage lifecycle of all
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:41,000 --> 00:06:46,000
|
| 351 |
+
instances in the app in spring, the full scope of all beans a single singleton.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:47,000 --> 00:06:52,000
|
| 355 |
+
In this case, responsibility for managing lifecycle is transferred to spring and that is fine.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:53,000 --> 00:06:59,000
|
| 359 |
+
But what to do in case you need Singleton and you don't have such container like in spring or in IGB.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:59,000 --> 00:07:01,000
|
| 363 |
+
So this point is discussable.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:01,000 --> 00:07:08,000
|
| 367 |
+
The second thing why some people hate Singleton is about static nature inside its implementation.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:08,000 --> 00:07:09,000
|
| 371 |
+
And you know what?
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:09,000 --> 00:07:15,000
|
| 375 |
+
Sometimes people just hate and sinks without getting deeper understanding of what actually wrong and
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:15,000 --> 00:07:21,000
|
| 379 |
+
what is the impact, the true impact of state of nature inside Singleton will impact us in case our
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:21,000 --> 00:07:23,000
|
| 383 |
+
class share some state.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:24,000 --> 00:07:30,000
|
| 387 |
+
So imagine in case our order management service would have some fields and the masses would modify the
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:30,000 --> 00:07:33,000
|
| 391 |
+
state of this object and take into account.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:33,000 --> 00:07:35,000
|
| 395 |
+
We have only one instance of this type.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:35,000 --> 00:07:41,000
|
| 399 |
+
We are constantly changing its state and impacting calculations in other parts of our program.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:41,000 --> 00:07:43,000
|
| 403 |
+
And this is really a true issue.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:43,000 --> 00:07:48,000
|
| 407 |
+
But we shouldn't implement Singleton pardon for types that should have some state.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:48,000 --> 00:07:55,000
|
| 411 |
+
Remember, it is very hard to gauge the effects in case our singleton doesn't have fields and any state.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:55,000 --> 00:08:00,000
|
| 415 |
+
Such types of objects are called stateless and case object is a stateless.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:00,000 --> 00:08:04,000
|
| 419 |
+
You shouldn't face was any negative consequences of Singleton.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:04,000 --> 00:08:10,000
|
| 423 |
+
And the sad things that some people is concerned about is impact during the testing of Singleton.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:10,000 --> 00:08:16,000
|
| 427 |
+
But I would say that this has potential impact of some static nature inside the singleton, because
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:16,000 --> 00:08:22,000
|
| 431 |
+
in case you want to create multiple units and run them one after another, you should come up with a
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:22,000 --> 00:08:28,000
|
| 435 |
+
mechanism that resets the state of the object on the test because you won't be able to create another
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:28,000 --> 00:08:32,000
|
| 439 |
+
instance during the test like you usually do in the testing.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:33,000 --> 00:08:38,000
|
| 443 |
+
So as you can see, the Singleton part is not so bad as somebody can imagine.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:38,000 --> 00:08:43,000
|
| 447 |
+
And to summarize our dogs around Singleton Parren, I want to simplify your life.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:43,000 --> 00:08:46,000
|
| 451 |
+
And that's why I made a simple checklist of all.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:46,000 --> 00:08:48,000
|
| 455 |
+
In case you want to implement Singleton pardon.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:48,000 --> 00:08:49,000
|
| 459 |
+
Here it is.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:49,000 --> 00:08:56,000
|
| 463 |
+
Define a private static field in the Singleton class, make constructor a private, implement public
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:56,000 --> 00:09:03,000
|
| 467 |
+
access or function implementation internalization that is creation on first use inside the accessor
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:03,000 --> 00:09:03,000
|
| 471 |
+
function.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:04,000 --> 00:09:10,000
|
| 475 |
+
Make sure that accessor function is synchronized in case it is going to be used in multiple training
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:10,000 --> 00:09:10,000
|
| 479 |
+
environment.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:11,000 --> 00:09:13,000
|
| 483 |
+
I think that set about Singleton.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:13,000 --> 00:09:19,000
|
| 487 |
+
Let's roll the new part now and the next part from our list is a prototype parren.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:19,000 --> 00:09:26,000
|
| 491 |
+
What is the intention of this Spartan prototype supposed to simplify project instantiation process by
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:26,000 --> 00:09:31,000
|
| 495 |
+
providing us with prototypes to create complex objects faster without new keyword?
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:32,000 --> 00:09:38,000
|
| 499 |
+
Because sometimes composing new object can take a lot of lines of code and specific domain knowledge
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:38,000 --> 00:09:39,000
|
| 503 |
+
of the system.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:39,000 --> 00:09:40,000
|
| 507 |
+
How to construct object.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:41,000 --> 00:09:46,000
|
| 511 |
+
Multiply this by amount of times to create new objects of such type in your system and you will come
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:46,000 --> 00:09:51,000
|
| 515 |
+
up with a year to create objects by Clonan prototype that should be easier.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:52,000 --> 00:09:54,000
|
| 519 |
+
Imagines a real life example.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:54,000 --> 00:09:58,000
|
| 523 |
+
Have some file on your computer that you want to copy to another directory.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:59,000 --> 00:10:01,000
|
| 527 |
+
You press control and see your file to.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:02,000 --> 00:10:08,000
|
| 531 |
+
To paste it in another directory later, this is just one of real life examples that demonstrate when
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:08,000 --> 00:10:15,000
|
| 535 |
+
you might need to create a new object based on another one inside your code, you can clone any object
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:15,000 --> 00:10:17,000
|
| 539 |
+
like this to create its copy.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:17,000 --> 00:10:24,000
|
| 543 |
+
Let's look at the demo to understand this part and better and to understand example on Java, make sure
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:24,000 --> 00:10:30,000
|
| 547 |
+
that you are familiar with glowing objects concept in Java, because from a technical standpoint, implementation
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:30,000 --> 00:10:35,000
|
| 551 |
+
of prototype depends on the implementation of Deep Clonan for specific object.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:35,000 --> 00:10:37,000
|
| 555 |
+
Let me show you an example.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:37,000 --> 00:10:40,000
|
| 559 |
+
Imagine that I have archival interface.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:40,000 --> 00:10:46,000
|
| 563 |
+
This type describes contract for all kinds of archives in my app that I'm going to use Turky files.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:46,000 --> 00:10:51,000
|
| 567 |
+
This type declares to Masset archive method itself and clone Macit.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:52,000 --> 00:10:56,000
|
| 571 |
+
We will implement Deep Clonan in all implementations of our Kivar type.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:57,000 --> 00:11:00,000
|
| 575 |
+
I hope that our cover interface looks clear for you.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:00,000 --> 00:11:02,000
|
| 579 |
+
Let's jump to implementations.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:02,000 --> 00:11:04,000
|
| 583 |
+
We have two implementations.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:04,000 --> 00:11:08,000
|
| 587 |
+
Zibakalam and Arikawa each implement archive Macel.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:09,000 --> 00:11:14,000
|
| 591 |
+
It is just a stop here for the sake of example and implementation of clone MassArt.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:14,000 --> 00:11:20,000
|
| 595 |
+
If you know how Clonan in Java works, you understand that Klown MassArt from Object Class makes shallow
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:20,000 --> 00:11:21,000
|
| 599 |
+
Cloyne.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:21,000 --> 00:11:25,000
|
| 603 |
+
That means Klown only references, but not actually cloning's.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:25,000 --> 00:11:29,000
|
| 607 |
+
The whole graph of objects that stands behind the references inside the class.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:29,000 --> 00:11:32,000
|
| 611 |
+
I mean, it's state that is described in fields.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:33,000 --> 00:11:38,000
|
| 615 |
+
So always keep in mind that no matter what programming language you use, you should implement Deep
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:38,000 --> 00:11:46,000
|
| 619 |
+
Clonan of object to provide external interface to Kornet, thereby implement prototype baaden and to
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:46,000 --> 00:11:47,000
|
| 623 |
+
easily implemented Clonan.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:47,000 --> 00:11:53,000
|
| 627 |
+
I use out of the box method of serialization utils from Aperture Command Library.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:53,000 --> 00:11:56,000
|
| 631 |
+
It also requires MakeMyTrip serializable.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:57,000 --> 00:12:01,000
|
| 635 |
+
In case you are interested in incentivisation, feel free to check my lesson from Java course about
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:01,000 --> 00:12:02,000
|
| 639 |
+
serialisation.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:03,000 --> 00:12:09,000
|
| 643 |
+
Now, when we have implementation to clone, let's think for a second how user will interact with our
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:09,000 --> 00:12:15,000
|
| 647 |
+
prototypes, how to provide clients of our code with conformable interface to create objects from our
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:15,000 --> 00:12:16,000
|
| 651 |
+
prototypes.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:16,000 --> 00:12:19,000
|
| 655 |
+
There are different ways to address this question.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:19,000 --> 00:12:25,000
|
| 659 |
+
I will show you just one of the possible solutions that I hope will work for you in your specific case.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:25,000 --> 00:12:27,000
|
| 663 |
+
I create archive a factory.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:27,000 --> 00:12:34,000
|
| 667 |
+
This is class that can generate objects of different types that are compatible with our Kivar interface
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:34,000 --> 00:12:41,000
|
| 671 |
+
and a car factory has prototypes, map and in reconciliation block and just at different objects that
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:41,000 --> 00:12:46,000
|
| 675 |
+
will be used as original objects to clone mapped with some string.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:46,000 --> 00:12:53,000
|
| 679 |
+
Also, the factory introduced public static method called get prototype for a type that takes string
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:53,000 --> 00:12:59,000
|
| 683 |
+
as an argument and returns clone of our prototype based on the requested archive type.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:00,000 --> 00:13:05,000
|
| 687 |
+
Does it make sense for the video for a second and think about this solution?
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:05,000 --> 00:13:11,000
|
| 691 |
+
I believe that this is a very elegant solution of the problem and when it comes to actually using the
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:11,000 --> 00:13:15,000
|
| 695 |
+
prototypes you can use archive a factory like this.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:15,000 --> 00:13:22,000
|
| 699 |
+
Imagine that at runtime you have request for different archives and you have two strings ZIB and there
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:22,000 --> 00:13:29,000
|
| 703 |
+
are you just use our cover factory and request our cover from it to call archive Masset on received
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:29,000 --> 00:13:30,000
|
| 707 |
+
object.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:30,000 --> 00:13:31,000
|
| 711 |
+
Let me execute the program.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:32,000 --> 00:13:38,000
|
| 715 |
+
So as you can see during the runtime, I get new clients based on my prototypes and they've worked just
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:38,000 --> 00:13:39,000
|
| 719 |
+
perfect.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:39,000 --> 00:13:45,000
|
| 723 |
+
Hobbs's this complete example helps you to understand how prototype model is implemented.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:45,000 --> 00:13:49,000
|
| 727 |
+
Let's look through the checklist that you will use when you will implement a prototype.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:49,000 --> 00:13:50,000
|
| 731 |
+
Pardon.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:51,000 --> 00:13:56,000
|
| 735 |
+
The first item in our list is to add clone Masset to the Iraqi of our objects.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:56,000 --> 00:14:02,000
|
| 739 |
+
The next thing would be to design a registry that maintains a cache of prototypic objects.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:03,000 --> 00:14:09,000
|
| 743 |
+
That is exactly the moment when we created factory class in our example with original prototypical objects
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:09,000 --> 00:14:10,000
|
| 747 |
+
in it.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:10,000 --> 00:14:17,000
|
| 751 |
+
Remember next design APIs that allow us to clone objects inside the factory and return new objects as
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:17,000 --> 00:14:23,000
|
| 755 |
+
a result, use factory API instead of new keyword to instantiate the objects.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:23,000 --> 00:14:24,000
|
| 759 |
+
That's it.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:25,000 --> 00:14:25,000
|
| 763 |
+
Let's move on.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:26,000 --> 00:14:31,000
|
| 767 |
+
The next button is a factor mass at the idea factory mass.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:31,000 --> 00:14:37,000
|
| 771 |
+
It is to define an interface, to create object, but let subclasses decide what concrete object to
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:37,000 --> 00:14:40,000
|
| 775 |
+
choose and what actual class to instantiate.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:40,000 --> 00:14:46,000
|
| 779 |
+
We need to factor in mass it in cases when we need to standardize the architectural model for a range
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:46,000 --> 00:14:47,000
|
| 783 |
+
of applications.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:47,000 --> 00:14:51,000
|
| 787 |
+
But each application decides what object is to instantiate.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:51,000 --> 00:14:58,000
|
| 791 |
+
And this example is just one of possible examples where factory mass is applicable in real life.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:58,000 --> 00:15:01,000
|
| 795 |
+
You will see that we are going to use flexible methods also in.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:01,000 --> 00:15:09,000
|
| 799 |
+
Partners such as abasic factory people often use Factory Masset as a standard way to create objects,
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:09,000 --> 00:15:16,000
|
| 803 |
+
but it is necessary if the class that instantiated never changes or instantiation takes place in an
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:16,000 --> 00:15:22,000
|
| 807 |
+
operation that subclauses can easily override, such as an initialization operation.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:22,000 --> 00:15:28,000
|
| 811 |
+
Let's look at example to understand how it works and to help you understand this person will use previous
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:28,000 --> 00:15:30,000
|
| 815 |
+
example with our covers.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:30,000 --> 00:15:33,000
|
| 819 |
+
So here is our cover interface from the previous example.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:34,000 --> 00:15:36,000
|
| 823 |
+
We don't need it anymore.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:36,000 --> 00:15:39,000
|
| 827 |
+
Since I'm going to show you factory pardon.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:39,000 --> 00:15:42,000
|
| 831 |
+
We have the same implementation of our current interface.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:43,000 --> 00:15:47,000
|
| 835 |
+
We have the Panama cover and our cover factory is different.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:47,000 --> 00:15:54,000
|
| 839 |
+
I have Massoud here get our cover and this Massoud retransmit different objects of our cover interface
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:54,000 --> 00:15:56,000
|
| 843 |
+
based on the string that I passed to it.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:57,000 --> 00:16:03,000
|
| 847 |
+
How exactly does it I also want to say that you will find different variations of such parren.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:03,000 --> 00:16:09,000
|
| 851 |
+
In some examples you will see that there are multiple if alse blocks here to call constructor to instantiate
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:09,000 --> 00:16:13,000
|
| 855 |
+
specific type and some examples I even saw swich block.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:13,000 --> 00:16:15,000
|
| 859 |
+
That is not the best decision.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:15,000 --> 00:16:21,000
|
| 863 |
+
Take into account you are going to have long and unreadable if else statement in case you have a lot
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:21,000 --> 00:16:22,000
|
| 867 |
+
of different implementations.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:23,000 --> 00:16:29,000
|
| 871 |
+
And also this approach will require you to update the source code approach that I suggest here, takes
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:29,000 --> 00:16:36,000
|
| 875 |
+
less lines of code and easily customizable in case you use some Iot container like spring containers
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:36,000 --> 00:16:39,000
|
| 879 |
+
that will produce new beans for you on the request.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:39,000 --> 00:16:45,000
|
| 883 |
+
In that case, I will be able easily reuse a solution and add new types by adjusting the configuration
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:45,000 --> 00:16:46,000
|
| 887 |
+
XML file.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:46,000 --> 00:16:53,000
|
| 891 |
+
In my solution, I create a map with a clever type string and function that generates new object of
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:53,000 --> 00:16:54,000
|
| 895 |
+
this specific type.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:55,000 --> 00:16:56,000
|
| 899 |
+
What is this function?
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:16:56,000 --> 00:17:01,000
|
| 903 |
+
This is a constructor and you know that function that takes nothing but your chance.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:01,000 --> 00:17:05,000
|
| 907 |
+
Something in Java called supplier, if you don't remember that.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:05,000 --> 00:17:12,000
|
| 911 |
+
Feel free to check functional programming section of my Java course and then static initialization block
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:12,000 --> 00:17:17,000
|
| 915 |
+
IMAP type strings with constructors with the help of method references.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:17,000 --> 00:17:18,000
|
| 919 |
+
Great.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:18,000 --> 00:17:25,000
|
| 923 |
+
And now I use ternary operator to implement Geter camera Macit in case I can't find such Mappin in Map
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:25,000 --> 00:17:26,000
|
| 927 |
+
Original.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:27,000 --> 00:17:34,000
|
| 931 |
+
In case there is some mapping, I execute this function and by interface contract in suppliers we have
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:34,000 --> 00:17:35,000
|
| 935 |
+
got MassArt.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:35,000 --> 00:17:37,000
|
| 939 |
+
That's why I called it here.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:37,000 --> 00:17:39,000
|
| 943 |
+
Let's look at Democrats now.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:17:40,000 --> 00:17:46,000
|
| 947 |
+
I just use factory method to instantiate the objects and run the program and you can see UNcancel.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:17:46,000 --> 00:17:52,000
|
| 951 |
+
We have different outputs produced by two different objects also to prove you that factory generates
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:17:52,000 --> 00:17:53,000
|
| 955 |
+
new objects.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:17:53,000 --> 00:17:59,000
|
| 959 |
+
Each time I generated one more zip archive and compared it with existing one with equals operator.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:00,000 --> 00:18:02,000
|
| 963 |
+
And you can see in console's that the result is false.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:03,000 --> 00:18:08,000
|
| 967 |
+
That means these two references are pointing out different objects in hip memory.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:08,000 --> 00:18:09,000
|
| 971 |
+
Does it make sense?
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:10,000 --> 00:18:15,000
|
| 975 |
+
In case you still have some questions, let me know by asking it in comments to this video.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:15,000 --> 00:18:21,000
|
| 979 |
+
Now let's recap factory partyin and create a checklist for its implementation in the future.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:21,000 --> 00:18:25,000
|
| 983 |
+
The first thing we need to do is to define hierarchy of objects.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:25,000 --> 00:18:31,000
|
| 987 |
+
As you can see, Factory Masset use inheritance mechanism to provide you with the object of type that
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:18:31,000 --> 00:18:32,000
|
| 991 |
+
you need.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:18:32,000 --> 00:18:37,000
|
| 995 |
+
The next thing to do is to design the arguments to the factor in NASSP.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:18:37,000 --> 00:18:44,000
|
| 999 |
+
Think about qualities or characteristics that are necessary and sufficient to identify the correct derived
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:18:44,000 --> 00:18:51,000
|
| 1003 |
+
class to instantiate in our specific example, we used only string was our current name, but actually
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:18:51,000 --> 00:18:56,000
|
| 1007 |
+
it can be a set of arguments called factory matter during the runtime to instantiate the object that
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:18:56,000 --> 00:18:57,000
|
| 1011 |
+
you need.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:18:58,000 --> 00:18:58,000
|
| 1015 |
+
Great.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:18:58,000 --> 00:19:03,000
|
| 1019 |
+
Well, really done with recreational pardons to more pardons from this group left.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:04,000 --> 00:19:07,000
|
| 1023 |
+
The next point that we are going to learn is build a pardon.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:07,000 --> 00:19:09,000
|
| 1027 |
+
Why we might need to build a pardon.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:10,000 --> 00:19:16,000
|
| 1031 |
+
Imagine that you have a complex object to build and you want to come up with the API that will allow
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:16,000 --> 00:19:20,000
|
| 1035 |
+
you easily to define what exact version of object you would like to construct.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:19:21,000 --> 00:19:27,000
|
| 1039 |
+
In other words, imagine the case when an application needs to create the elements of a complex aggregate.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:19:28,000 --> 00:19:32,000
|
| 1043 |
+
And the interesting thing about Builder is that you can find different variations of the builder.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:19:32,000 --> 00:19:33,000
|
| 1047 |
+
Pardon?
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:19:33,000 --> 00:19:38,000
|
| 1051 |
+
Does it actually solve our original problem but implemented in different ways?
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:19:38,000 --> 00:19:44,000
|
| 1055 |
+
For example, there is a variation of partner with director class that is responsible for building objects.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:19:44,000 --> 00:19:50,000
|
| 1059 |
+
And also there is a variation of builder patterns that called chain builder and allows to build new
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:19:50,000 --> 00:19:52,000
|
| 1063 |
+
objects step by step.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:19:52,000 --> 00:19:57,000
|
| 1067 |
+
Personally, I believe that the second variation is more popular, but I want to share with you all.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:19:57,000 --> 00:20:01,000
|
| 1071 |
+
Variations with examples will start from builder Partan.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:01,000 --> 00:20:03,000
|
| 1075 |
+
Implementation was director.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:03,000 --> 00:20:09,000
|
| 1079 |
+
Imagine that you need to build a computer and you have computer class and, you know, all properties
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:09,000 --> 00:20:10,000
|
| 1083 |
+
of computer.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:10,000 --> 00:20:16,000
|
| 1087 |
+
Let's look at it so simple computer class that has a display system, block and manipulators.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:17,000 --> 00:20:18,000
|
| 1091 |
+
We have computer builders type.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:19,000 --> 00:20:19,000
|
| 1095 |
+
Here it is.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:20,000 --> 00:20:26,000
|
| 1099 |
+
It has computer property, abstract assets to build each property of a computer, create new computer
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:20:26,000 --> 00:20:28,000
|
| 1103 |
+
Massett and get computer messages.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:20:28,000 --> 00:20:29,000
|
| 1107 |
+
It returns.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:20:29,000 --> 00:20:35,000
|
| 1111 |
+
A reference to the computer field, I believe you understood already, is that we need to create concrete
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:20:35,000 --> 00:20:38,000
|
| 1115 |
+
builders that will implement this absolute marcedes.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:20:39,000 --> 00:20:43,000
|
| 1119 |
+
In our example, we have cheap computer builder and expensive computer builder.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:20:44,000 --> 00:20:50,000
|
| 1123 |
+
The main thing is that you have to understand here is that these built methods change the state of our
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:20:50,000 --> 00:20:51,000
|
| 1127 |
+
computer object.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:20:52,000 --> 00:20:56,000
|
| 1131 |
+
Take into account this a child classes of my absolute computer builder.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:20:56,000 --> 00:21:01,000
|
| 1135 |
+
I have access to computer property inside this class to take into account.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:01,000 --> 00:21:04,000
|
| 1139 |
+
In our example, the computer has only string properties.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:04,000 --> 00:21:10,000
|
| 1143 |
+
I just said different strings, but in real life, all construction, the logic of each field will be
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:21:10,000 --> 00:21:11,000
|
| 1147 |
+
placed here.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:21:12,000 --> 00:21:18,000
|
| 1151 |
+
OK, now when we have different computer builders, we need to have a director that knows how to organize
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:21:18,000 --> 00:21:21,000
|
| 1155 |
+
the work of builders to produce expected result.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:21:21,000 --> 00:21:23,000
|
| 1159 |
+
We have computer director Glass here.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:21:24,000 --> 00:21:27,000
|
| 1163 |
+
As you can see, it aggregates computer builder inside.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:21:27,000 --> 00:21:30,000
|
| 1167 |
+
And this builder we can pass to the constructor.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:21:30,000 --> 00:21:36,000
|
| 1171 |
+
We have built computer MassArt, where I build computer by delegating work to my builder.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:21:36,000 --> 00:21:40,000
|
| 1175 |
+
And after that I can provide build computer on a separate request.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:21:41,000 --> 00:21:43,000
|
| 1179 |
+
I'm talking about get computer Macit.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:21:43,000 --> 00:21:50,000
|
| 1183 |
+
This architecture allows me to substitute the builder on the fly and build new computer based on that
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:21:50,000 --> 00:21:56,000
|
| 1187 |
+
as a builder, or build a series of the same computers without passing the same data multiple times,
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:21:56,000 --> 00:21:56,000
|
| 1191 |
+
etc..
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:21:56,000 --> 00:21:59,000
|
| 1195 |
+
Constructor of computer class auto setters.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:22:00,000 --> 00:22:01,000
|
| 1199 |
+
Does it make sense so far?
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:22:02,000 --> 00:22:06,000
|
| 1203 |
+
Presuppose for me minute to understand how these classes are connected.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:22:06,000 --> 00:22:13,000
|
| 1207 |
+
And by the way, you will find references to the source code of all examples in attachments to this
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:22:13,000 --> 00:22:13,000
|
| 1211 |
+
lesson.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:22:13,000 --> 00:22:19,000
|
| 1215 |
+
It is just a regular git repository, so you can basically just put the repository on your local computer
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:22:19,000 --> 00:22:21,000
|
| 1219 |
+
and investigate the source code.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:22:21,000 --> 00:22:22,000
|
| 1223 |
+
Let's continue.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:22:23,000 --> 00:22:27,000
|
| 1227 |
+
Here is a client of our code and here you can see how builder pattern will work.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:22:28,000 --> 00:22:34,000
|
| 1231 |
+
I great director and based on the current needs, I can set different builder after that and build a
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:22:34,000 --> 00:22:37,000
|
| 1235 |
+
computer and retrieve computer from director.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:22:37,000 --> 00:22:38,000
|
| 1239 |
+
That's it.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:22:38,000 --> 00:22:45,000
|
| 1243 |
+
So much preparations for done to achieve the simplicity in building complex objects and being able to
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:22:45,000 --> 00:22:46,000
|
| 1247 |
+
change boolean logic on the fly.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:22:47,000 --> 00:22:52,000
|
| 1251 |
+
And here you can see that I set a new builder, expensive computer builder this time and built a new
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:22:52,000 --> 00:22:55,000
|
| 1255 |
+
computer and printed it again to console.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:22:56,000 --> 00:22:57,000
|
| 1259 |
+
Let me run this program.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:22:57,000 --> 00:23:03,000
|
| 1263 |
+
And in console output you can see that we managed to build different computers, cheap and expensive
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:23:03,000 --> 00:23:03,000
|
| 1267 |
+
one.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:23:04,000 --> 00:23:08,000
|
| 1271 |
+
Is it clear how this version of builder pattern is clear?
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:23:08,000 --> 00:23:12,000
|
| 1275 |
+
Let's review another version of builder pattern chain builder.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:23:12,000 --> 00:23:14,000
|
| 1279 |
+
The idea here is simple.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:23:14,000 --> 00:23:19,000
|
| 1283 |
+
We have a class that has builder inside it that knows how to build the object.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:23:19,000 --> 00:23:26,000
|
| 1287 |
+
Each method of the builder returns the reference to builder object to call next method enchained like
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:23:26,000 --> 00:23:29,000
|
| 1291 |
+
style take into account builder is an inner class.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:23:30,000 --> 00:23:32,000
|
| 1295 |
+
It has access to all fields from auto class.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:23:33,000 --> 00:23:34,000
|
| 1299 |
+
She restudy.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:23:34,000 --> 00:23:38,000
|
| 1303 |
+
Can you build a method that creates builder based on that account object?
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:23:38,000 --> 00:23:41,000
|
| 1307 |
+
Here is the inner class builder.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:23:41,000 --> 00:23:46,000
|
| 1311 |
+
It has private constructor so that nobody from the outside could create and build the object.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:23:47,000 --> 00:23:52,000
|
| 1315 |
+
And after that we have satyrs methods that initialize the state of our account object.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:23:52,000 --> 00:23:59,000
|
| 1319 |
+
And each time Setas returns the reference to the current object as a current builder, this trick allows
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:23:59,000 --> 00:24:03,000
|
| 1323 |
+
us to build change by calling the next message on our builder.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:24:03,000 --> 00:24:07,000
|
| 1327 |
+
And we have a special method to terminate a chain of locations.
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:24:07,000 --> 00:24:14,000
|
| 1331 |
+
This is built MassArt built Macit returns as a reference to already built and constructed object.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:24:14,000 --> 00:24:17,000
|
| 1335 |
+
Let's look at the client code to understand how it works.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:24:18,000 --> 00:24:25,000
|
| 1339 |
+
I call the new build an asset and after that I build a chain of satyrs that I need and this chain is
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:24:25,000 --> 00:24:26,000
|
| 1343 |
+
terminated.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:24:26,000 --> 00:24:26,000
|
| 1347 |
+
Was built.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:24:26,000 --> 00:24:29,000
|
| 1351 |
+
Masset That's how I get my account object.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:24:30,000 --> 00:24:37,000
|
| 1355 |
+
This architecture allows me to build objects a step by step and initialize on those properties of my
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:24:37,000 --> 00:24:39,000
|
| 1359 |
+
future object that I need help.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:24:39,000 --> 00:24:41,000
|
| 1363 |
+
This example make things clearer.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:24:42,000 --> 00:24:46,000
|
| 1367 |
+
Let's now come up with a checklist to implement a canonical builder and change builder.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:24:46,000 --> 00:24:49,000
|
| 1371 |
+
Partner to implement builder partner with director.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:24:49,000 --> 00:24:56,000
|
| 1375 |
+
We have to declare builder interface, create multiple builders, create directors that can work with
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:24:56,000 --> 00:25:02,000
|
| 1379 |
+
different builders in client code, instantiate director and can create implementation of builder to
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:25:02,000 --> 00:25:07,000
|
| 1383 |
+
build new objects to implement builder Padrón with Chain Massett.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:25:07,000 --> 00:25:14,000
|
| 1387 |
+
Course we have to create inner builder class insight type that we want to build implement method in
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:25:14,000 --> 00:25:20,000
|
| 1391 |
+
type that returns reference to the builder object, the clear satyrs and builder that returns the reference
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:25:20,000 --> 00:25:28,000
|
| 1395 |
+
to this builder object implement build MassArt to terminate massive chain and return target object in
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:25:28,000 --> 00:25:33,000
|
| 1399 |
+
client code called Masset to get reference to build and build object step by step.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:25:33,000 --> 00:25:35,000
|
| 1403 |
+
Basically that's it.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:25:35,000 --> 00:25:36,000
|
| 1407 |
+
Regarding Builder Pardon.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:25:36,000 --> 00:25:37,000
|
| 1411 |
+
Let's move on.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:25:37,000 --> 00:25:41,000
|
| 1415 |
+
And the last but not the least plan for today is an abstract factory.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:25:41,000 --> 00:25:47,000
|
| 1419 |
+
We need abstract factory for cases when we need to create a group of interdependent classes.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:25:47,000 --> 00:25:54,000
|
| 1423 |
+
By implementing abstract factory part, we define an interface for families of objects without specification
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:25:54,000 --> 00:25:56,000
|
| 1427 |
+
of concrete class.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:25:56,000 --> 00:25:59,000
|
| 1431 |
+
To understand this person, let me explain an example.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:26:00,000 --> 00:26:02,000
|
| 1435 |
+
Look at the class diagrams that you see on the slide.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:26:03,000 --> 00:26:09,000
|
| 1439 |
+
Imagine that we are working on the desktop application and we need to create Pop-Up Window that is specific
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:26:09,000 --> 00:26:10,000
|
| 1443 |
+
for each operating system.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:26:11,000 --> 00:26:11,000
|
| 1447 |
+
I mean.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:26:11,000 --> 00:26:17,000
|
| 1451 |
+
Michael, as we have close window button on the top left corner in Microsoft Windows, we have close
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:26:17,000 --> 00:26:22,000
|
| 1455 |
+
button on top right corner and we have a different styling of scrolls and balance.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:26:22,000 --> 00:26:27,000
|
| 1459 |
+
That's why we have two abstract factories for Microsoft Windows and for Mac OS.
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:26:27,000 --> 00:26:32,000
|
| 1463 |
+
Each factory can build Windows that contains only objects that should be used together.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:26:33,000 --> 00:26:40,000
|
| 1467 |
+
So in this task, when I create a window, I need to create a set of objects, models, scroll content
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:26:40,000 --> 00:26:41,000
|
| 1471 |
+
area and so on.
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:26:41,000 --> 00:26:47,000
|
| 1475 |
+
And I can create a scroll for windows and combine it with Macarius buttons, understand?
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:26:48,000 --> 00:26:53,000
|
| 1479 |
+
That's why we can talk about family of objects that can work together with each other.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:26:54,000 --> 00:27:00,000
|
| 1483 |
+
I will pass my abstract factory to Gwai builder so that GWI builder can use abstract factories to create
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:27:00,000 --> 00:27:02,000
|
| 1487 |
+
all necessary elements for my window.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:27:03,000 --> 00:27:04,000
|
| 1491 |
+
Does it make sense?
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:27:04,000 --> 00:27:11,000
|
| 1495 |
+
I can explain in theory, but to be honest, personally, for me this part wasn't obvious until I saw
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:27:11,000 --> 00:27:12,000
|
| 1499 |
+
a real life example.
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:27:12,000 --> 00:27:14,000
|
| 1503 |
+
So let's jump to an example.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:27:15,000 --> 00:27:18,000
|
| 1507 |
+
Let's start our demo from Abstract Factory itself.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:27:18,000 --> 00:27:24,000
|
| 1511 |
+
Here is my abstract widget factory that declares three masses, masses that should create within itself
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:27:24,000 --> 00:27:29,000
|
| 1515 |
+
a method that creates growth methods, that creates an array of navigation buttons.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:27:30,000 --> 00:27:32,000
|
| 1519 |
+
Can you recognize what these methods remind you?
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:27:33,000 --> 00:27:35,000
|
| 1523 |
+
They look like factory masses.
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:27:35,000 --> 00:27:42,000
|
| 1527 |
+
Does this abstract factory and abstract methods here will be implemented for different families of objects?
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:27:42,000 --> 00:27:51,000
|
| 1531 |
+
I have Mac OS Widget Factory and a mass widget factory and you can see that in each class I create objects
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:27:51,000 --> 00:27:52,000
|
| 1535 |
+
that should work well with each other.
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:27:53,000 --> 00:28:00,000
|
| 1539 |
+
For Marco s widget, I create macro as window marker scroll and a Mac or as buttons for Microsoft Windows
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:28:00,000 --> 00:28:01,000
|
| 1543 |
+
algorithms window.
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:28:01,000 --> 00:28:03,000
|
| 1547 |
+
I must scroll Annemasse buttons.
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:28:03,000 --> 00:28:04,000
|
| 1551 |
+
Does it make sense?
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:28:05,000 --> 00:28:07,000
|
| 1555 |
+
Next I have Gwai builder.
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:28:07,000 --> 00:28:11,000
|
| 1559 |
+
I can pastorate any concrete implementation of abstract factory.
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:28:11,000 --> 00:28:18,000
|
| 1563 |
+
I have go builder will use this API to build all necessary elements and display them properly.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:28:19,000 --> 00:28:21,000
|
| 1567 |
+
Now let me open my demo file.
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:28:21,000 --> 00:28:27,000
|
| 1571 |
+
You can see that I create Gwai Builder and after that, based on the user input or app configurations,
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:28:27,000 --> 00:28:28,000
|
| 1575 |
+
it doesn't matter.
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:28:28,000 --> 00:28:34,000
|
| 1579 |
+
I can take information about the operating system from different places, but when I know operating
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:28:34,000 --> 00:28:42,000
|
| 1583 |
+
system, I initialize my widget factory and call build window Masset, bypassing that my abstract factory.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:28:42,000 --> 00:28:48,000
|
| 1587 |
+
That is how Abstract Factory pardon helps us to deal with instantiation of family of objects.
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:28:48,000 --> 00:28:51,000
|
| 1591 |
+
Now let's come up with a checklist that you need to follow.
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:28:51,000 --> 00:28:58,000
|
| 1595 |
+
When you want to implement abstract factory pattern, implement class groups or so-called type families,
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:28:58,000 --> 00:29:04,000
|
| 1599 |
+
you declare abstract factory interface with factory masset per product use abstract factory to instantiate
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:29:04,000 --> 00:29:11,000
|
| 1603 |
+
group of related objects, homes that now abstract factory part doesn't look like something scary.
|
| 1604 |
+
|
| 1605 |
+
402
|
| 1606 |
+
00:29:11,000 --> 00:29:16,000
|
| 1607 |
+
And before we call it today, let's understand what is the difference between Factory MassArt and Abstract
|
| 1608 |
+
|
| 1609 |
+
403
|
| 1610 |
+
00:29:16,000 --> 00:29:17,000
|
| 1611 |
+
Factory?
|
| 1612 |
+
|
| 1613 |
+
404
|
| 1614 |
+
00:29:17,000 --> 00:29:19,000
|
| 1615 |
+
I would like to list a few differences.
|
| 1616 |
+
|
| 1617 |
+
405
|
| 1618 |
+
00:29:19,000 --> 00:29:24,000
|
| 1619 |
+
Zaya Factory Method focuses on generation of one single object.
|
| 1620 |
+
|
| 1621 |
+
406
|
| 1622 |
+
00:29:24,000 --> 00:29:30,000
|
| 1623 |
+
Various abstract factory should solve the issue of instantiate and group of related objects.
|
| 1624 |
+
|
| 1625 |
+
407
|
| 1626 |
+
00:29:31,000 --> 00:29:37,000
|
| 1627 |
+
Factory Mass can be part of abstract factory, but also factory masad can exist independently.
|
| 1628 |
+
|
| 1629 |
+
408
|
| 1630 |
+
00:29:37,000 --> 00:29:43,000
|
| 1631 |
+
When we are talking about factory Masset, we mean one method that can generate a specific object.
|
| 1632 |
+
|
| 1633 |
+
409
|
| 1634 |
+
00:29:43,000 --> 00:29:49,000
|
| 1635 |
+
But when we are talking about abstract factory women, the type that may contain many different methods
|
| 1636 |
+
|
| 1637 |
+
410
|
| 1638 |
+
00:29:49,000 --> 00:29:55,000
|
| 1639 |
+
that help us to create a group of objects, factory methods relies on inheritance mechanism.
|
| 1640 |
+
|
| 1641 |
+
411
|
| 1642 |
+
00:29:56,000 --> 00:30:01,000
|
| 1643 |
+
It allows subclasses to decide what implementation of specific type to generate.
|
| 1644 |
+
|
| 1645 |
+
412
|
| 1646 |
+
00:30:01,000 --> 00:30:07,000
|
| 1647 |
+
But in abstract factory, the main focus is on generating multiple objects from one family that are
|
| 1648 |
+
|
| 1649 |
+
413
|
| 1650 |
+
00:30:07,000 --> 00:30:10,000
|
| 1651 |
+
not connected within one Iraqi home.
|
| 1652 |
+
|
| 1653 |
+
414
|
| 1654 |
+
00:30:10,000 --> 00:30:12,000
|
| 1655 |
+
That visualisations on the slide.
|
| 1656 |
+
|
| 1657 |
+
415
|
| 1658 |
+
00:30:12,000 --> 00:30:15,000
|
| 1659 |
+
And my explanation helps you to understand the difference.
|
| 1660 |
+
|
| 1661 |
+
416
|
| 1662 |
+
00:30:16,000 --> 00:30:22,000
|
| 1663 |
+
Now, let's recap what we have learned today in this lesson, we learned five correlational golf partners
|
| 1664 |
+
|
| 1665 |
+
417
|
| 1666 |
+
00:30:22,000 --> 00:30:29,000
|
| 1667 |
+
after this lesson, I believe, you know, Singleton prototype factory, MassArt builder and absolute
|
| 1668 |
+
|
| 1669 |
+
418
|
| 1670 |
+
00:30:29,000 --> 00:30:30,000
|
| 1671 |
+
factory pardon's.
|
| 1672 |
+
|
| 1673 |
+
419
|
| 1674 |
+
00:30:31,000 --> 00:30:31,000
|
| 1675 |
+
That's it.
|
| 1676 |
+
|
| 1677 |
+
420
|
| 1678 |
+
00:30:32,000 --> 00:30:33,000
|
| 1679 |
+
Thanks a lot for your attention.
|
| 1680 |
+
|
| 1681 |
+
421
|
| 1682 |
+
00:30:33,000 --> 00:30:33,000
|
| 1683 |
+
Yes.
|
| 1684 |
+
|
| 1685 |
+
422
|
| 1686 |
+
00:30:33,000 --> 00:30:36,000
|
| 1687 |
+
Students, see you in the next lesson.
|
| 1688 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/002 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/creational
|
39 - GoF Design Patterns of Software Architecture in OOP/003 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello, dear students.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:12,000
|
| 7 |
+
We proceed learning golf patterns, and in this lesson, we are going to learn structural patterns by
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:12,000
|
| 11 |
+
this moment.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:12,000 --> 00:00:18,000
|
| 15 |
+
You are already familiar with overview of structural patterns, and I hope you had time to learn creation
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:18,000 --> 00:00:19,000
|
| 19 |
+
of part unseen details.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:20,000 --> 00:00:25,000
|
| 23 |
+
And today we are going to start learning the most popular structural patterns and our plans to run to
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:25,000 --> 00:00:29,000
|
| 27 |
+
the next Spartans proxy decorator, adaptor and facade.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:30,000 --> 00:00:33,000
|
| 31 |
+
The rest of the structural partners will learn in another lesson.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:34,000 --> 00:00:39,000
|
| 35 |
+
Also, I will try to focus your attention on the differences between these partners to make sure your
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:39,000 --> 00:00:40,000
|
| 39 |
+
clearest separates them.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:41,000 --> 00:00:45,000
|
| 43 |
+
After this lesson, you will know how to create more complex structures with different units.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:46,000 --> 00:00:51,000
|
| 47 |
+
Also in this lesson, you are going to see a lot of code examples that will help you to understand this
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:51,000 --> 00:00:52,000
|
| 51 |
+
topic better.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:53,000 --> 00:00:57,000
|
| 55 |
+
All code examples that you will see in this lesson attached to this video.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:58,000 --> 00:01:02,000
|
| 59 |
+
Let's start, and the first point that we are going to learn today is proxy.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:02,000 --> 00:01:08,000
|
| 63 |
+
The goal of this spartan is the following we want to protect some object of direct impact.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:09,000 --> 00:01:15,000
|
| 67 |
+
Also, we want to control interactions with the object and trigger unnecessary behavior if needed.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:15,000 --> 00:01:21,000
|
| 71 |
+
When we will use proxy power, for example, one you don't want to create a real object because it is
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:21,000 --> 00:01:27,000
|
| 75 |
+
big and you want to postpone instantiation process to the moment when the object will be needed.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:28,000 --> 00:01:34,000
|
| 79 |
+
At the mean time, you can initialize variables with the proxy object to avoid null pointer exception
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:34,000 --> 00:01:38,000
|
| 83 |
+
and initialize a real object on the first request to proxy.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:38,000 --> 00:01:44,000
|
| 87 |
+
The next case when you want to use proxy point is to control interactions with the object.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:44,000 --> 00:01:49,000
|
| 91 |
+
The simplest real life example is proxies that we use in the internet.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:49,000 --> 00:01:53,000
|
| 95 |
+
Imagine that in your company, you have a list of restricted resources.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:54,000 --> 00:02:00,000
|
| 99 |
+
For example, your employer restricts that Instagram and Facebook to make sure that nobody spends broken
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:00,000 --> 00:02:02,000
|
| 103 |
+
time in the social networks.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:02,000 --> 00:02:06,000
|
| 107 |
+
Just an example how your boss can implement this rule.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:06,000 --> 00:02:11,000
|
| 111 |
+
It will use proxy server when your browser will send a request to a specific web site.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:11,000 --> 00:02:18,000
|
| 115 |
+
It will go through a proxy server that will validate the URL in your request with the restricted ones.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:18,000 --> 00:02:24,000
|
| 119 |
+
In the case the website, your request is bond, but your organization rules you will receive connection
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:24,000 --> 00:02:25,000
|
| 123 |
+
error.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:25,000 --> 00:02:28,000
|
| 127 |
+
That's one of the examples of using proxies.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:28,000 --> 00:02:34,000
|
| 131 |
+
Also, your face was proxies in spring framework, especially in aspect oriented program.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:35,000 --> 00:02:39,000
|
| 135 |
+
In case you don't know what is aspect oriented programming, no worries, adult.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:40,000 --> 00:02:44,000
|
| 139 |
+
I'll explain it now in simple words following definition from Wikipedia.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:44,000 --> 00:02:51,000
|
| 143 |
+
Aspect oriented programming AOP is a programming paradigm that aims to increase maturity by allowing
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:51,000 --> 00:02:54,000
|
| 147 |
+
the separation of cross-cutting concerns.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:54,000 --> 00:02:57,000
|
| 151 |
+
To be honest, even from users, definition is not clear.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:58,000 --> 00:02:59,000
|
| 155 |
+
Let me explain this in my words.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:00,000 --> 00:03:03,000
|
| 159 |
+
Imagine that you have some code already written.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:03,000 --> 00:03:08,000
|
| 163 |
+
Let's say some code that places order in database when customer presses by button.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:09,000 --> 00:03:15,000
|
| 167 |
+
And now you don't want on Justice Court, but you want to add additional behavior to this event.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:16,000 --> 00:03:22,000
|
| 171 |
+
Now you want to also to send emails to administrators at order has been placed 10th place order in database.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:22,000 --> 00:03:29,000
|
| 175 |
+
As usual, you can add so-called advice to the existing code and you can implement this with proxy.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:30,000 --> 00:03:35,000
|
| 179 |
+
You create wrapper around a regional object and track requests that were sent to it.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:36,000 --> 00:03:39,000
|
| 183 |
+
And depending on the request, you can add additional behavior.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:39,000 --> 00:03:40,000
|
| 187 |
+
Does it make sense?
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:41,000 --> 00:03:47,000
|
| 191 |
+
While this is also an example of proxy pardon, it is hard to demo today in case you have never heard
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:47,000 --> 00:03:49,000
|
| 195 |
+
about aspects around this program.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:49,000 --> 00:03:54,000
|
| 199 |
+
We learned this in adolescence and will have a little bit simpler example.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:55,000 --> 00:04:01,000
|
| 203 |
+
Also, other examples that you might already use in the unit and integration testing in Java.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:01,000 --> 00:04:03,000
|
| 207 |
+
We have Makita and is a mock library.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:04,000 --> 00:04:09,000
|
| 211 |
+
And even in other programming languages, you have libraries that help us to create test doubles.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:09,000 --> 00:04:12,000
|
| 215 |
+
Do remember such as double aspi.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:12,000 --> 00:04:13,000
|
| 219 |
+
Let me remind you quickly.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:14,000 --> 00:04:20,000
|
| 223 |
+
SPI is a test double that behaves like a real object beside masses that are stopped beforehand, such
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:20,000 --> 00:04:27,000
|
| 227 |
+
as double in most cases implemented with the help of proxy pardon, the wrapper is created and the original
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:27,000 --> 00:04:30,000
|
| 231 |
+
object, and each mass at invocation is controlled.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:30,000 --> 00:04:37,000
|
| 235 |
+
Is it clear home that now you understood, in simple words, why we need proxy partners sometimes?
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:37,000 --> 00:04:40,000
|
| 239 |
+
And what problem it's supposed to solve?
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:40,000 --> 00:04:44,000
|
| 243 |
+
Now let's look at code example to understand proxy power and better.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:45,000 --> 00:04:47,000
|
| 247 |
+
I prepared the example of internet proxy.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:47,000 --> 00:04:50,000
|
| 251 |
+
Imagine that we have some interface called internet.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:51,000 --> 00:04:58,000
|
| 255 |
+
This interface declares only one behavior in our example connect the host and takes URL as an argument.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:59,000 --> 00:05:01,000
|
| 259 |
+
We have implementation of this interface.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:02,000 --> 00:05:05,000
|
| 263 |
+
Called it default internet by default.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:05,000 --> 00:05:07,000
|
| 267 |
+
It just prints you around to console.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:08,000 --> 00:05:13,000
|
| 271 |
+
And now I'm going to create a proxy proxy should implement the same interface.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:14,000 --> 00:05:15,000
|
| 275 |
+
Here's my proxy internet.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:16,000 --> 00:05:23,000
|
| 279 |
+
As you can see, it also implements the same interface, and it aggregates default internet inside,
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:24,000 --> 00:05:26,000
|
| 283 |
+
so it drops the default internet object.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:27,000 --> 00:05:29,000
|
| 287 |
+
We have list of bond websites here.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:30,000 --> 00:05:32,000
|
| 291 |
+
It can be Facebook and Instagram, for example.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:33,000 --> 00:05:39,000
|
| 295 |
+
Just how would employees sitting in social networks all day and when connect, the host method is invoked?
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:39,000 --> 00:05:43,000
|
| 299 |
+
I verify it was a somebody trying to access the website.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:44,000 --> 00:05:47,000
|
| 303 |
+
If yes, then I throw an exception.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:47,000 --> 00:05:50,000
|
| 307 |
+
If no, then I proceed with internet connection.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:50,000 --> 00:05:52,000
|
| 311 |
+
Does it make sense so far?
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:52,000 --> 00:05:59,000
|
| 315 |
+
Press a pause for a minute and look at this proxy one more time and try to understand how I dropped
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:59,000 --> 00:06:03,000
|
| 319 |
+
default internet object here and delegated calls to.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:03,000 --> 00:06:07,000
|
| 323 |
+
If everything is clear for you now, let's create a checklist to follow.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:07,000 --> 00:06:14,000
|
| 327 |
+
In case you want to implement proxy pardon, so the implement proxy portal would need to follow next
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:14,000 --> 00:06:14,000
|
| 331 |
+
steps.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:15,000 --> 00:06:22,000
|
| 335 |
+
The interface for wrapper and for regional type create proxy type that implements the current interface.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:23,000 --> 00:06:26,000
|
| 339 |
+
Aggregate objects that you want to wrap in your proxy type.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:27,000 --> 00:06:30,000
|
| 343 |
+
Implement logic of interaction with the original object.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:30,000 --> 00:06:31,000
|
| 347 |
+
That's it.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:32,000 --> 00:06:39,000
|
| 351 |
+
Regarding some items to consider, some engineers might say that introducing proxy is just about having
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:39,000 --> 00:06:42,000
|
| 355 |
+
additional level of obstruction, and they will be right.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:43,000 --> 00:06:48,000
|
| 359 |
+
But remember, we're having this level of abstraction to benefit from it, not just to have it.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:49,000 --> 00:06:54,000
|
| 363 |
+
So analyze your particular case and decide whether proxy is needed in your case.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:55,000 --> 00:06:58,000
|
| 367 |
+
If everything is clear here, let's learn new bottom.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:58,000 --> 00:07:05,000
|
| 371 |
+
Let me presented decorator part, and let's try to understand what it is that can reach a part and allows
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:05,000 --> 00:07:12,000
|
| 375 |
+
us to structure objects in such a way that allows us to add new features to already existing objects.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:12,000 --> 00:07:19,000
|
| 379 |
+
You can attach new behavior and extend existing one decorators, a flexible alternative to the inheritance
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:19,000 --> 00:07:21,000
|
| 383 |
+
mechanism for extending the functionality.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:22,000 --> 00:07:28,000
|
| 387 |
+
Implementation of this button allows you to add new features to already constructed objects and to understand,
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:28,000 --> 00:07:29,000
|
| 391 |
+
decorate and better.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:30,000 --> 00:07:37,000
|
| 395 |
+
Always keep in mind input output package in Java In case you didn't know Java yet or forgot the specifics
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:37,000 --> 00:07:44,000
|
| 399 |
+
of this package, I will remind you in i o package in Java, we can create objects of input stream,
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:44,000 --> 00:07:50,000
|
| 403 |
+
and after we created this object, we can rob it was buffered input stream decorator.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:51,000 --> 00:07:56,000
|
| 407 |
+
In other words, we are able to add ability to use buffer during the reading.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:57,000 --> 00:08:02,000
|
| 411 |
+
And moreover, if we want, then we can rob this new object with another one.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:02,000 --> 00:08:09,000
|
| 415 |
+
For example, data input stream that allows us to read data in specific Java data type links shared
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:09,000 --> 00:08:16,000
|
| 419 |
+
by Char, Boolean, etc. And we can do this Robin as many times as we want.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:16,000 --> 00:08:19,000
|
| 423 |
+
That's how Decorator works at the end of the day.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:20,000 --> 00:08:26,000
|
| 427 |
+
It is just not possible to describe all variations of all possible types with different features.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:26,000 --> 00:08:33,000
|
| 431 |
+
Sometimes it is easier to read and the user, in our case, to engineer to decide object with which
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:33,000 --> 00:08:36,000
|
| 435 |
+
specific features he or she would like to construct.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:37,000 --> 00:08:38,000
|
| 439 |
+
Does it make sense?
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:38,000 --> 00:08:46,000
|
| 443 |
+
As I already said, one of the simplest and most popular clear examples of decorator pardon is i o package
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:46,000 --> 00:08:46,000
|
| 447 |
+
in G Decay.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:47,000 --> 00:08:50,000
|
| 451 |
+
Feel free to investigate how a decorator is implemented z.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:51,000 --> 00:08:56,000
|
| 455 |
+
But still, I think it might be not super obvious at first glance.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:56,000 --> 00:08:58,000
|
| 459 |
+
That's why I would still prefer to explain.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:58,000 --> 00:09:00,000
|
| 463 |
+
Is this partly on this simple example?
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:01,000 --> 00:09:07,000
|
| 467 |
+
Imagine that we are developing some racing again, whether the need for speed video game and we need
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:07,000 --> 00:09:09,000
|
| 471 |
+
to program logic for different type of cars.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:09,000 --> 00:09:12,000
|
| 475 |
+
For example, we are going to have some regular car.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:12,000 --> 00:09:14,000
|
| 479 |
+
It could be any curves.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:14,000 --> 00:09:21,000
|
| 483 |
+
Those that we see on the streets each day also will have features of luxury and sports car, and we
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:21,000 --> 00:09:23,000
|
| 487 |
+
will be able to combine these features.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:24,000 --> 00:09:29,000
|
| 491 |
+
For example, we will create luxury sport or just sports or just luxury car.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:30,000 --> 00:09:31,000
|
| 495 |
+
Now, pay attention.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:31,000 --> 00:09:33,000
|
| 499 |
+
How will structure our types here?
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:34,000 --> 00:09:39,000
|
| 503 |
+
First of all, we need to define an interface of our car time here at this.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:40,000 --> 00:09:46,000
|
| 507 |
+
To simplify this example, let's pretend that we have only one massive drive and before construction
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:46,000 --> 00:09:49,000
|
| 511 |
+
of complex object by adding new feature to it.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:49,000 --> 00:09:54,000
|
| 515 |
+
We need to have at least some basic object that will be used as a base.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:55,000 --> 00:10:01,000
|
| 519 |
+
That's why the first things that I did, I created this basic car class that implements current interface.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:02,000 --> 00:10:08,000
|
| 523 |
+
As you can see, there is a default implementation that just prints text to console about the fact that
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:08,000 --> 00:10:15,000
|
| 527 |
+
the basic current drives now and want to implement the car interface in car, decorate the gloss.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:15,000 --> 00:10:19,000
|
| 531 |
+
This gloss will describe the logic of adding additional features to cart.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:20,000 --> 00:10:22,000
|
| 535 |
+
Here is the car decorator class.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:23,000 --> 00:10:23,000
|
| 539 |
+
Pay attention.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:23,000 --> 00:10:26,000
|
| 543 |
+
The decorator implements the same interface.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:27,000 --> 00:10:31,000
|
| 547 |
+
In this particular case, I also aggregate car object in sight.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:31,000 --> 00:10:38,000
|
| 551 |
+
I can't grade can't decorate that without another car and when drive mass is invoked.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:38,000 --> 00:10:41,000
|
| 555 |
+
You see that I called Drive Massad on this car.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:42,000 --> 00:10:45,000
|
| 559 |
+
Press a pause for a second to understand this.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:45,000 --> 00:10:53,000
|
| 563 |
+
In this case, I can build a chain of objects that wraps each other and invokes specific variation of
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:53,000 --> 00:10:54,000
|
| 567 |
+
the same behavior.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:55,000 --> 00:11:00,000
|
| 571 |
+
And again, in your particular case, this mascot may be rewritten as you wish.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:01,000 --> 00:11:02,000
|
| 575 |
+
And as it will work for your logic.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:03,000 --> 00:11:08,000
|
| 579 |
+
Now let me show you classes that describe specific features to be added to the basic car.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:09,000 --> 00:11:13,000
|
| 583 |
+
As I mentioned before, we have sports car and luxury car.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:13,000 --> 00:11:15,000
|
| 587 |
+
Let's start from luxury car first.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:16,000 --> 00:11:19,000
|
| 591 |
+
You can see that it extends car decorator.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:19,000 --> 00:11:21,000
|
| 595 |
+
It takes car as an argument.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:22,000 --> 00:11:27,000
|
| 599 |
+
We override drive massive here so that we call parent and drive massive.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:28,000 --> 00:11:34,000
|
| 603 |
+
The one we have just reviewed in car decorator to invoke drive mass on aggregated car first.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:35,000 --> 00:11:42,000
|
| 607 |
+
And after that, in this massive additional behavior, in our case, it is just printing additional
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:42,000 --> 00:11:43,000
|
| 611 |
+
text to consult.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:44,000 --> 00:11:49,000
|
| 615 |
+
But I believe it is clear for you that you can actually describe any as little logic here.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:49,000 --> 00:11:53,000
|
| 619 |
+
Also, pay attention that you can't create just a luxury car.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:54,000 --> 00:11:58,000
|
| 623 |
+
You can't build a luxury car only on the basis of some other car.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:58,000 --> 00:12:02,000
|
| 627 |
+
That's why it is necessary to pass this car to constructor.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:02,000 --> 00:12:03,000
|
| 631 |
+
Is that clear?
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:04,000 --> 00:12:07,000
|
| 635 |
+
And in sports car, we have pretty similar situation.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:07,000 --> 00:12:12,000
|
| 639 |
+
The only difference is just the behavior in drive mass is a little bit different.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:12,000 --> 00:12:17,000
|
| 643 |
+
I print another text to reflects the fact that this is sports car driving.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:18,000 --> 00:12:22,000
|
| 647 |
+
But in the real life, you can implement any logic you think is needed here.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:22,000 --> 00:12:25,000
|
| 651 |
+
And one more important thing was decorator.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:25,000 --> 00:12:28,000
|
| 655 |
+
You're not limited only to override in some behavior.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:29,000 --> 00:12:35,000
|
| 659 |
+
You're able and welcome to introduce enhanced interface and new behavior by wrapping basic objects.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:36,000 --> 00:12:38,000
|
| 663 |
+
And also, you can declare additional fields if you need.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:39,000 --> 00:12:45,000
|
| 667 |
+
For example, here in sports car, I can declare additional behaviors that is valid for sports cars.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:46,000 --> 00:12:52,000
|
| 671 |
+
Set transmission mode If you ever draw Porsche or Ferrari, you know that they have different drive
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:52,000 --> 00:12:58,000
|
| 675 |
+
modes that tuned suspension of your car exhaust transmission and other things.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:58,000 --> 00:13:05,000
|
| 679 |
+
For example, in the Porsche 911, you have regular mode sport and Sport Plus and this mass, it will
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:05,000 --> 00:13:08,000
|
| 683 |
+
help us to set the transmission mode in our car.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:09,000 --> 00:13:15,000
|
| 687 |
+
Ideally, it would take in them, but in our simplified example, it takes any string as an argument.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:16,000 --> 00:13:23,000
|
| 691 |
+
And now the most interesting part is a client part and see how we can construct objects following this
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:23,000 --> 00:13:23,000
|
| 695 |
+
architecture.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:24,000 --> 00:13:28,000
|
| 699 |
+
I have them across here where I collected everything in one place.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:28,000 --> 00:13:32,000
|
| 703 |
+
Let me run the program first to walk you through the console output.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:32,000 --> 00:13:38,000
|
| 707 |
+
As you can see, I create a basic car first and cold drive massive.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:38,000 --> 00:13:42,000
|
| 711 |
+
Afterwards, I decided to create a sports car to create it.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:42,000 --> 00:13:48,000
|
| 715 |
+
I need to create new object of basic car and pass it to constructor of sports car.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:49,000 --> 00:13:57,000
|
| 719 |
+
Here you can see that sports car wraps basic car, and when I call Drive Mass on sports car, you can
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:57,000 --> 00:13:59,000
|
| 723 |
+
see that basic car behavior works first.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:00,000 --> 00:14:07,000
|
| 727 |
+
And after that feature of sports car worked and again, it's only up to you how you will ride this logic.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:07,000 --> 00:14:14,000
|
| 731 |
+
You can even during cold drive mass of basic car, but just use some other behavior of basic object.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:14,000 --> 00:14:18,000
|
| 735 |
+
For example, Basic Car also has four wheels.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:18,000 --> 00:14:20,000
|
| 739 |
+
You can just work with those properties.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:21,000 --> 00:14:24,000
|
| 743 |
+
We can initialize variable of specific type like with you.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:24,000 --> 00:14:31,000
|
| 747 |
+
Here was sports car, and in this case, you have access to sports car specific behavior like we described
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:32,000 --> 00:14:33,000
|
| 751 |
+
set transmission mode.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:33,000 --> 00:14:36,000
|
| 755 |
+
So you can see how was decorated spartan.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:36,000 --> 00:14:43,000
|
| 759 |
+
I enhanced existent interface and having this flexibility, I can create objects with different features
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:43,000 --> 00:14:44,000
|
| 763 |
+
and variations.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:44,000 --> 00:14:48,000
|
| 767 |
+
For example, I can create sports and luxury car if I wish.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:49,000 --> 00:14:50,000
|
| 771 |
+
How to do that?
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:50,000 --> 00:14:57,000
|
| 775 |
+
The decorator part and allows us to pass new objects inside the constructor to wrap objects as many
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:57,000 --> 00:14:58,000
|
| 779 |
+
times as I need.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:59,000 --> 00:15:01,000
|
| 783 |
+
As you can see here, I just wrapped.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:01,000 --> 00:15:08,000
|
| 787 |
+
Objects multiple times, and when I call drive massive, I can see behavior of basic car.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:08,000 --> 00:15:12,000
|
| 791 |
+
Luxury car and sports car, can you see this?
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:13,000 --> 00:15:19,000
|
| 795 |
+
And in this case, you don't need to apply inheritance mechanism to create all possible combinations
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:19,000 --> 00:15:20,000
|
| 799 |
+
of different types.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:20,000 --> 00:15:25,000
|
| 803 |
+
You can just construct neurons and runtime object with features that you need.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:25,000 --> 00:15:26,000
|
| 807 |
+
Isn't this cool?
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:27,000 --> 00:15:31,000
|
| 811 |
+
Now you know how to implement decorator part in your application.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:32,000 --> 00:15:36,000
|
| 815 |
+
Let's now check the checklist to follow to implement decorator part.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:36,000 --> 00:15:42,000
|
| 819 |
+
And the first thing you need to do is to ensure that you have a common context also called core.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:43,000 --> 00:15:47,000
|
| 823 |
+
Like in our case, we have some basic car like an i o package.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:47,000 --> 00:15:49,000
|
| 827 |
+
We have some basic input stream type.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:50,000 --> 00:15:55,000
|
| 831 |
+
You should have at least some core component and list of features that you would like to add to it.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:56,000 --> 00:16:03,000
|
| 835 |
+
After that, create a decorator type score, gloss and decorate the gloss implements the same common
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:03,000 --> 00:16:05,000
|
| 839 |
+
interface with common context.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:16:06,000 --> 00:16:12,000
|
| 843 |
+
Implement different features that can be added to the common context by extending or implementing decorator
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:16:12,000 --> 00:16:12,000
|
| 847 |
+
type.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:13,000 --> 00:16:17,000
|
| 851 |
+
Implement additional and enhanced functionality in decorator classes.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:18,000 --> 00:16:24,000
|
| 855 |
+
Those are items that we went through during the implementation of Decorator part in our example homes.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:24,000 --> 00:16:25,000
|
| 859 |
+
That was a source code.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:25,000 --> 00:16:28,000
|
| 863 |
+
It was easier for you to understand the Spartan.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:28,000 --> 00:16:36,000
|
| 867 |
+
Now, when we are done with decorate pardon, let's proceed with the next one and the next part is adapter.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:36,000 --> 00:16:42,000
|
| 871 |
+
And as always, let's understand first what problem adaptive pardon is supposed to address.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:42,000 --> 00:16:49,000
|
| 875 |
+
Imagine that you already have some type that do exactly what you need, but the interface is incompatible
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:49,000 --> 00:16:51,000
|
| 879 |
+
with the one you have in your system.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:52,000 --> 00:16:56,000
|
| 883 |
+
It can be because of the different reasons some of them are.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:56,000 --> 00:17:04,000
|
| 887 |
+
You are migrating part of your system and some interfaces are not matching each other or you are dealing
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:17:04,000 --> 00:17:12,000
|
| 891 |
+
with obsolete code and you can't just remove it because it works just fine or you want to use some third
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:17:12,000 --> 00:17:18,000
|
| 895 |
+
party library, but it has a different interface that doesn't match needs and agreements within your
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:17:18,000 --> 00:17:19,000
|
| 899 |
+
module.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:19,000 --> 00:17:22,000
|
| 903 |
+
What solution you have to apply to solve this?
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:22,000 --> 00:17:30,000
|
| 907 |
+
Just implement a doctor that helps to support existing interface and map it against another interface
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:30,000 --> 00:17:35,000
|
| 911 |
+
similar to the different types of sockets when you travel to Great Britain.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:35,000 --> 00:17:41,000
|
| 915 |
+
You need specific adapter when you travel to United States, you need another adapter.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:41,000 --> 00:17:47,000
|
| 919 |
+
When you travel to Europe or Russia, you need some type of adapter to plug in your device.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:47,000 --> 00:17:48,000
|
| 923 |
+
Does it make sense?
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:49,000 --> 00:17:55,000
|
| 927 |
+
Similar to this example, you can implement adapter in your code to adapt one interface to another.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:56,000 --> 00:17:59,000
|
| 931 |
+
In other words, we can see that adapter wraps.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:59,000 --> 00:18:07,000
|
| 935 |
+
Existing class was a new interface code we use, which always was a hard thing to follow and to implement
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:18:07,000 --> 00:18:10,000
|
| 939 |
+
and adopt to pardon should help us with this.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:18:10,000 --> 00:18:13,000
|
| 943 |
+
Hope you already understood what do we need and up to?
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:14,000 --> 00:18:18,000
|
| 947 |
+
And now let's review code examples to learn the sport and better.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:18,000 --> 00:18:25,000
|
| 951 |
+
Imagine that we have sought an interface that's supposed to sort array of ins across my app, and I
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:25,000 --> 00:18:32,000
|
| 955 |
+
use it already in OSM, massive declarations in different places across my app and the margins that
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:32,000 --> 00:18:34,000
|
| 959 |
+
I have third party library.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:34,000 --> 00:18:42,000
|
| 963 |
+
That source list of integers and then does its work just perfect and source faster than all gnome algorithms?
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:42,000 --> 00:18:44,000
|
| 967 |
+
This is so-called no sorted.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:45,000 --> 00:18:45,000
|
| 971 |
+
Here it is.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:46,000 --> 00:18:51,000
|
| 975 |
+
According to its interface, it takes list of integers, but not array offense.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:51,000 --> 00:18:55,000
|
| 979 |
+
Here, you can imagine any times that you might have in your system.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:55,000 --> 00:19:01,000
|
| 983 |
+
The main thing to understand here is that you have some specific interface and massive signature.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:19:02,000 --> 00:19:07,000
|
| 987 |
+
In our case, this is sorta interface and you use it across your app.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:07,000 --> 00:19:10,000
|
| 991 |
+
You already have mass that accepts only such type.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:10,000 --> 00:19:13,000
|
| 995 |
+
It can be different variations of the same issue.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:13,000 --> 00:19:19,000
|
| 999 |
+
And now imagine that you need to search array of things, but you have new algorithms in the search
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:19,000 --> 00:19:26,000
|
| 1003 |
+
party, a library that is significantly faster and you want to use it in the application, but also
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:26,000 --> 00:19:29,000
|
| 1007 |
+
you don't want a break and isn't else in your program.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:29,000 --> 00:19:37,000
|
| 1011 |
+
What has been already written before and probably even oversimplified this example, but this is just
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:37,000 --> 00:19:42,000
|
| 1015 |
+
to make it clear for all my students who see adoptive parents first time in their lives.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:42,000 --> 00:19:46,000
|
| 1019 |
+
Definitely, you can create the least from array and vice versa.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:46,000 --> 00:19:47,000
|
| 1023 |
+
And that's it.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:47,000 --> 00:19:54,000
|
| 1027 |
+
But point is in the fact that you don't want to do this all the times and also you don't want it to
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:54,000 --> 00:19:56,000
|
| 1031 |
+
fix all places where you will use this.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:57,000 --> 00:20:00,000
|
| 1035 |
+
And moreover, such case may happen with Stipe's.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:00,000 --> 00:20:01,000
|
| 1039 |
+
That is not easy to.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:01,000 --> 00:20:06,000
|
| 1043 |
+
The road between each other as array of ends and list of integers.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:06,000 --> 00:20:09,000
|
| 1047 |
+
But again, this is just a simple example.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:20:09,000 --> 00:20:16,000
|
| 1051 |
+
So what we have to do is the easiest thing would be to find a way out to adapt the existence sort of
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:16,000 --> 00:20:20,000
|
| 1055 |
+
interface to no sorter to make it sort of ends.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:20,000 --> 00:20:27,000
|
| 1059 |
+
I agree why I need to think how to implement faster and more efficient algorithm of sorting array of
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:27,000 --> 00:20:28,000
|
| 1063 |
+
things.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:28,000 --> 00:20:34,000
|
| 1067 |
+
If I have another class that do approximately the same things that I need in this specific case, I
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:34,000 --> 00:20:36,000
|
| 1071 |
+
need to come up with that doctor.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:37,000 --> 00:20:44,000
|
| 1075 |
+
Here's my short list adopter pay attention that it implements my sort of interface that is basically
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:44,000 --> 00:20:48,000
|
| 1079 |
+
interface that I already use across my whole app.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:48,000 --> 00:20:53,000
|
| 1083 |
+
I aggregate numbers sorter here inside and once stored mass.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:53,000 --> 00:20:57,000
|
| 1087 |
+
It is called I convert array of fields to list of integers.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:58,000 --> 00:21:00,000
|
| 1091 |
+
It to my number soldier.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:21:00,000 --> 00:21:06,000
|
| 1095 |
+
Since it is already works with lists of integers and when sorting is completed, I convert it back to
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:21:06,000 --> 00:21:08,000
|
| 1099 |
+
a reference to return from the message.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:09,000 --> 00:21:16,000
|
| 1103 |
+
Now you can see that actually I have the interface that they need, but I adapted the implementation
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:16,000 --> 00:21:18,000
|
| 1107 |
+
to make it work with third party library.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:18,000 --> 00:21:19,000
|
| 1111 |
+
Can you see this?
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:21:20,000 --> 00:21:23,000
|
| 1115 |
+
Let's investigate now client code together.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:21:23,000 --> 00:21:30,000
|
| 1119 |
+
Here we have a real fence, and it is obvious that in the case, I would use third party library directly
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:21:30,000 --> 00:21:31,000
|
| 1123 |
+
to search my array.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:21:31,000 --> 00:21:35,000
|
| 1127 |
+
It wouldn't work because Matter's signature is different.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:21:36,000 --> 00:21:43,000
|
| 1131 |
+
After that, I initialize my certainly adopted and you can see that I can refer to this object was the
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:21:43,000 --> 00:21:51,000
|
| 1135 |
+
reference of type sorter that is my interface, and I can use my interface that is already used across
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:51,000 --> 00:21:52,000
|
| 1139 |
+
my program.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:52,000 --> 00:22:01,000
|
| 1143 |
+
So I just call sort massive and pos array of ins inside it is converted, the list of integers sorted
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:22:01,000 --> 00:22:02,000
|
| 1147 |
+
and converted bacteria fence.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:22:03,000 --> 00:22:05,000
|
| 1151 |
+
Does it make more sense now?
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:22:05,000 --> 00:22:09,000
|
| 1155 |
+
And again, I would recommend you to pause the video here.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:22:09,000 --> 00:22:15,000
|
| 1159 |
+
Make sure you downloaded the source code from attachments to this lesson and reviewed by yourself.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:22:15,000 --> 00:22:21,000
|
| 1163 |
+
Hopefully, my comments makes sense, and now it is easier for you to understand how adoptive parent
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:22:21,000 --> 00:22:22,000
|
| 1167 |
+
works.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:22:22,000 --> 00:22:29,000
|
| 1171 |
+
Now let's create a checklist to implement adaptive part and identifies the interface that you need to
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:22:29,000 --> 00:22:29,000
|
| 1175 |
+
follow.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:22:29,000 --> 00:22:35,000
|
| 1179 |
+
In our case, it was sorta interface identified times that you need to adapt.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:22:35,000 --> 00:22:44,000
|
| 1183 |
+
In our case, it was no sorta great adopters that implements target interface and aggregates Typekit
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:22:44,000 --> 00:22:51,000
|
| 1187 |
+
that you need to adapt wrapper G+ should have as a reference to the adaptive class in the final step
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:22:51,000 --> 00:22:54,000
|
| 1191 |
+
instantiate adapter in your client code and just use it.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:22:55,000 --> 00:22:56,000
|
| 1195 |
+
That's it.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:22:56,000 --> 00:23:02,000
|
| 1199 |
+
Hopefully, now it wouldn't be hard for you to implement adaptive porting from scratch when it will
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:23:02,000 --> 00:23:02,000
|
| 1203 |
+
be needed.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:23:03,000 --> 00:23:09,000
|
| 1207 |
+
Now let's learn the last but not least part for today I'd like to present a facade pardon.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:23:10,000 --> 00:23:11,000
|
| 1211 |
+
Why do we need it?
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:23:11,000 --> 00:23:13,000
|
| 1215 |
+
Let me explain an example.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:23:13,000 --> 00:23:19,000
|
| 1219 |
+
Imagine that you are implementing some e-commerce application and you are working with business to business
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:23:19,000 --> 00:23:19,000
|
| 1223 |
+
model.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:23:20,000 --> 00:23:27,000
|
| 1227 |
+
So-called B2B, sometimes registration of B2B customer that there's some legal entity is harder than
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:23:27,000 --> 00:23:29,000
|
| 1231 |
+
the registration of regular user.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:23:29,000 --> 00:23:35,000
|
| 1235 |
+
For example, there is might be cases that you have multiple systems on your one on one duplication
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:23:35,000 --> 00:23:42,000
|
| 1239 |
+
of records related to the same customer or you want a verified data of legal entity in other services
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:23:42,000 --> 00:23:48,000
|
| 1243 |
+
before registration and registration of new customer will take a few subsequent calls to different services.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:23:49,000 --> 00:23:55,000
|
| 1247 |
+
What do you think would be comfortable to develop and to support such a system having duplicated massive
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:23:55,000 --> 00:23:56,000
|
| 1251 |
+
invocations across your app?
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:23:57,000 --> 00:24:02,000
|
| 1255 |
+
And moreover, making mistake is easier when you have to remember the whole process of registration
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:24:02,000 --> 00:24:04,000
|
| 1259 |
+
for B2B customer.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:24:04,000 --> 00:24:09,000
|
| 1263 |
+
How to simplify the life of engineers and reduce development efforts and likelihood of mistakes.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:24:10,000 --> 00:24:14,000
|
| 1267 |
+
The proper solution here would be to introduce another level of abstraction here.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:24:14,000 --> 00:24:22,000
|
| 1271 |
+
So-called facade bottom helps us to create a unified interface to interact with set of interfaces or
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:24:22,000 --> 00:24:22,000
|
| 1275 |
+
subsystem.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:24:23,000 --> 00:24:28,000
|
| 1279 |
+
Facade defines a high level interface that makes a subsystem easier to use.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:24:28,000 --> 00:24:35,000
|
| 1283 |
+
Also, using facades, it makes it easier for new engineers who are joining your team to learn the system
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:24:35,000 --> 00:24:35,000
|
| 1287 |
+
faster.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:24:36,000 --> 00:24:42,000
|
| 1291 |
+
So I really feel really understood that the facade will become client interface to the set of other
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:24:42,000 --> 00:24:44,000
|
| 1295 |
+
types or subsystem.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:24:44,000 --> 00:24:51,000
|
| 1299 |
+
Probably the only thing that we need to know now is to how to apply this in practice and especially
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:24:51,000 --> 00:24:52,000
|
| 1303 |
+
for this.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:24:52,000 --> 00:24:57,000
|
| 1307 |
+
I prepared good examples that will help us to understand the sport and foster.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:24:57,000 --> 00:25:01,000
|
| 1311 |
+
Imagine that you are implementing travel booking system.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:25:01,000 --> 00:25:07,000
|
| 1315 |
+
And you need to allow end users to book travel route that includes flight, combined with the hotels
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:25:07,000 --> 00:25:09,000
|
| 1319 |
+
available as a selected date.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:25:09,000 --> 00:25:16,000
|
| 1323 |
+
So as a traveler, I want to book flights and the hotel available for me at that day.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:25:17,000 --> 00:25:23,000
|
| 1327 |
+
As you can see, I have specific business case that I need to implement and really feel ready to seize
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:25:23,000 --> 00:25:24,000
|
| 1331 |
+
the whole picture in the hat.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:25:25,000 --> 00:25:31,000
|
| 1335 |
+
Implementation of this scenario, which require declare and set of types like the following one's flight
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:25:31,000 --> 00:25:39,000
|
| 1339 |
+
hotel the book that is sometimes that can book hotel flight book that is times that can book flight
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:25:39,000 --> 00:25:40,000
|
| 1343 |
+
for US travel route.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:25:41,000 --> 00:25:46,000
|
| 1347 |
+
This is exactly the time that combines hotels with flights to create travel routes for tourists.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:25:47,000 --> 00:25:50,000
|
| 1351 |
+
And here is our travel facade and our specific example.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:25:50,000 --> 00:25:55,000
|
| 1355 |
+
It has only a few masses, but in real life it could be more massive here.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:25:55,000 --> 00:26:01,000
|
| 1359 |
+
We have masses for our specific business case, not least of travel rules that are available and book
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:26:01,000 --> 00:26:03,000
|
| 1363 |
+
specific travel routes.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:26:03,000 --> 00:26:10,000
|
| 1367 |
+
Here you can see that I aggregate auto and a flag book to get a list of available orders and flights
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:26:10,000 --> 00:26:13,000
|
| 1371 |
+
accordingly and book auto and flights.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:26:13,000 --> 00:26:19,000
|
| 1375 |
+
One user will select the travel route in the Jet Travel Routes Mass, and I can just grab the logic
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:26:19,000 --> 00:26:25,000
|
| 1379 |
+
of processing for flights and autos and mapping them between each other and creating of travel routes.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:26:26,000 --> 00:26:32,000
|
| 1383 |
+
After that, we reach a list of travel routes to not distract your attention on process and logic.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:26:32,000 --> 00:26:39,000
|
| 1387 |
+
I just put common here and return empty list to avoid compilation error and not going to run time exception.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:26:39,000 --> 00:26:45,000
|
| 1391 |
+
Hope you are not losing the focus from my instincts here in the book Travel Route Mass.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:26:45,000 --> 00:26:52,000
|
| 1395 |
+
I booked separately auto and flight, and now every time I book travel route, I just need to go one
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:26:52,000 --> 00:26:53,000
|
| 1399 |
+
mass at this one.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:26:54,000 --> 00:27:01,000
|
| 1403 |
+
Let me show you how client code looks like now is the only thing you need is just to create an instance
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:27:01,000 --> 00:27:06,000
|
| 1407 |
+
of travel facade wherever you need to get a list of travel routes and book travel.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:27:07,000 --> 00:27:13,000
|
| 1411 |
+
You can see how easily I can get lists of travel routes and how easily I can book travel route.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:27:13,000 --> 00:27:19,000
|
| 1415 |
+
Just imagine that every time in all places so your app you would need to instantiate flight, book auto
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:27:19,000 --> 00:27:23,000
|
| 1419 |
+
worker, describe logic of mapping and creation of travel routes.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:27:24,000 --> 00:27:25,000
|
| 1423 |
+
That is almost impossible.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:27:26,000 --> 00:27:29,000
|
| 1427 |
+
That's how facade may make our lives easier.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:27:29,000 --> 00:27:35,000
|
| 1431 |
+
You have just another level of abstraction, and you can interact with a subsystem through a simple
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:27:35,000 --> 00:27:36,000
|
| 1435 |
+
interface.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:27:37,000 --> 00:27:41,000
|
| 1439 |
+
You should always remember that your facade should not become an object.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:27:42,000 --> 00:27:45,000
|
| 1443 |
+
Gut object is an auntie pardon that describes the case.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:27:46,000 --> 00:27:49,000
|
| 1447 |
+
When you have objects is that can do everything in your app.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:27:50,000 --> 00:27:56,000
|
| 1451 |
+
For example, you have a facade that can register user, lock him and create a shopping cart for him.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:27:57,000 --> 00:27:58,000
|
| 1455 |
+
Checkout and so on.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:27:59,000 --> 00:28:06,000
|
| 1459 |
+
You can't do everything with the one object because this will violate or be principles and will bring
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:28:06,000 --> 00:28:10,000
|
| 1463 |
+
you to the high Coplan, which already know is not perfect.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:28:11,000 --> 00:28:17,000
|
| 1467 |
+
Basically, that sits regarding the facade pattern that's grab a checklist to implement facade bottom.
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:28:18,000 --> 00:28:24,000
|
| 1471 |
+
The first thing we need to start with is to define business cases and business scenarios that are most
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:28:24,000 --> 00:28:25,000
|
| 1475 |
+
used in your app.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:28:26,000 --> 00:28:32,000
|
| 1479 |
+
Design the facade interfaces are described to be here, but to interact with a subsystem, aggregate
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:28:32,000 --> 00:28:40,000
|
| 1483 |
+
all necessary types inside the facade to ensure efficient and proper behavior of facade in client code.
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:28:40,000 --> 00:28:43,000
|
| 1487 |
+
Get the essence of a facade and work with it.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:28:43,000 --> 00:28:50,000
|
| 1491 |
+
Now you can easily implement facade by your own windows and most popular structural points in this lesson,
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:28:50,000 --> 00:28:51,000
|
| 1495 |
+
in my opinion.
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:28:51,000 --> 00:28:59,000
|
| 1499 |
+
They are a proxy decorator, adopter and facade, and very often my students ask me what the specific
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:28:59,000 --> 00:29:01,000
|
| 1503 |
+
differences between these buttons.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:29:02,000 --> 00:29:05,000
|
| 1507 |
+
Because in some degree, ziff something in common.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:29:05,000 --> 00:29:08,000
|
| 1511 |
+
But I want you to see clear difference between them.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:29:09,000 --> 00:29:12,000
|
| 1515 |
+
So let's now covers the differences on this slide.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:29:12,000 --> 00:29:14,000
|
| 1519 |
+
Let's recap what this proxy pattern do.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:29:15,000 --> 00:29:20,000
|
| 1523 |
+
Proxy wraps as the object to avoid direct interaction with object.
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:29:21,000 --> 00:29:27,000
|
| 1527 |
+
Proxy provides the same interface as wrapped object and how this is different from decorate.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:29:27,000 --> 00:29:33,000
|
| 1531 |
+
The bottom decorator provides enhanced interface like you saw today.
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:29:33,000 --> 00:29:40,000
|
| 1535 |
+
In our example, when we decorated our car, this additional behavior and method so you can decorate
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:29:40,000 --> 00:29:41,000
|
| 1539 |
+
object was additional behavior.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:29:42,000 --> 00:29:49,000
|
| 1543 |
+
OK, but when I tell this, my students often ask me, and what is the difference between proxy decorator
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:29:49,000 --> 00:29:58,000
|
| 1547 |
+
and doctor that my doctor provides different interface to its object and adapts one interface to nazar?
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:29:58,000 --> 00:29:59,000
|
| 1551 |
+
Is that clear?
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:29:59,000 --> 00:30:01,000
|
| 1555 |
+
And then how facade?
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:30:01,000 --> 00:30:10,000
|
| 1559 |
+
Often is different facade also introduces new interface, but I job to introduce new interface that
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:30:10,000 --> 00:30:18,000
|
| 1563 |
+
respects a particular interface that it once thought that, on the other hand, facade is used when
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:30:18,000 --> 00:30:24,000
|
| 1567 |
+
you want to create new interface to make interaction with subsystem easier.
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:30:24,000 --> 00:30:32,000
|
| 1571 |
+
And very often by combining the behavior of multiple units into complete business flow, it makes sense.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:30:33,000 --> 00:30:37,000
|
| 1575 |
+
Hope now it is clear for you what is the difference between these buttons?
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:30:37,000 --> 00:30:43,000
|
| 1579 |
+
Now, let's recap what we have learned to date in this lesson we learned for partners.
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:30:43,000 --> 00:30:48,000
|
| 1583 |
+
They are a proxy decorator, adaptor and facade.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:30:48,000 --> 00:30:55,000
|
| 1587 |
+
Also, we performed comparative analysis of these parts so that you could clearly understand the difference
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:30:55,000 --> 00:30:56,000
|
| 1591 |
+
between them.
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:30:56,000 --> 00:30:58,000
|
| 1595 |
+
That's it for this lesson.
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:30:58,000 --> 00:31:00,000
|
| 1599 |
+
Thanks a lot for your attention.
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:31:00,000 --> 00:31:03,000
|
| 1603 |
+
Have a great day and see you in the next lesson.
|
| 1604 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/004 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/structural
|
39 - GoF Design Patterns of Software Architecture in OOP/004 Structural Patterns, p.2_en.srt
ADDED
|
@@ -0,0 +1,1144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello, my friends, and this lesson we learned in structural patterns and previous lessons we learned
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:19,000
|
| 7 |
+
proxy decorator and and facade pardon, that means we have three more parties from structural S. to
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:19,000 --> 00:00:23,000
|
| 11 |
+
learn in this lesson, build on bridge, lightweight and composite.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:24,000 --> 00:00:30,000
|
| 15 |
+
And as always, we learn these buttons with the help of coding examples that you can find in attachments
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:30,000 --> 00:00:31,000
|
| 19 |
+
to this lesson.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:32,000 --> 00:00:32,000
|
| 23 |
+
Nothing to say.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:32,000 --> 00:00:33,000
|
| 27 |
+
More about agenda.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:33,000 --> 00:00:34,000
|
| 31 |
+
Let's stop.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:35,000 --> 00:00:38,000
|
| 35 |
+
And the first part is that we are going to review today is a bridge.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:38,000 --> 00:00:45,000
|
| 39 |
+
But the main goal of Bridgepoint is to decouple an abstraction from its implementation so that the two
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:45,000 --> 00:00:47,000
|
| 43 |
+
can vary independently.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:47,000 --> 00:00:51,000
|
| 47 |
+
Let's try to understand what stands behind the statement.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:52,000 --> 00:00:58,000
|
| 51 |
+
Imagine the case when your class and what it is supposed to do will arise very often.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:58,000 --> 00:01:04,000
|
| 55 |
+
I mean, literally, you should go and change your class every time it changes the behavior.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:04,000 --> 00:01:10,000
|
| 59 |
+
Such cases are not very often, but it may happen that you would need to come up with a solution how
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:10,000 --> 00:01:12,000
|
| 63 |
+
to address constant changes in behavior.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:13,000 --> 00:01:17,000
|
| 67 |
+
But what if we would separate to terms abstraction and implementation?
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:18,000 --> 00:01:23,000
|
| 71 |
+
What if your class would be considered as relatively stable abstraction and you will keep implementation
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:23,000 --> 00:01:24,000
|
| 75 |
+
separately?
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:24,000 --> 00:01:27,000
|
| 79 |
+
That is exactly what each part is about.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:27,000 --> 00:01:33,000
|
| 83 |
+
Which point exists to address the challenge of constant behavior changes without impacting the code
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:33,000 --> 00:01:34,000
|
| 87 |
+
as it was already written?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:35,000 --> 00:01:37,000
|
| 91 |
+
Don't you think so?
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:37,000 --> 00:01:38,000
|
| 95 |
+
Was Bechuanaland way?
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:38,000 --> 00:01:44,000
|
| 99 |
+
We have abstraction and its implementation separated and that's why they may be improved separately
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:44,000 --> 00:01:45,000
|
| 103 |
+
without breach.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:45,000 --> 00:01:51,000
|
| 107 |
+
But when you have all implementations bound to the abstraction at compile time and this can be changed
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:51,000 --> 00:01:52,000
|
| 111 |
+
as the runtime.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:52,000 --> 00:01:56,000
|
| 115 |
+
How is the separation of abstraction and implementation is implemented?
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:56,000 --> 00:01:57,000
|
| 119 |
+
Very easy.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:57,000 --> 00:02:00,000
|
| 123 |
+
They're separated in different classes.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:00,000 --> 00:02:06,000
|
| 127 |
+
We should implement our abstraction with the possibility to delegate goals to our implementation.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:06,000 --> 00:02:12,000
|
| 131 |
+
In this case, we will be able to pass implementation during the runtime and update our behavior.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:12,000 --> 00:02:13,000
|
| 135 |
+
Does it make sense?
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:14,000 --> 00:02:18,000
|
| 139 |
+
If not yet, then let me explain this one example with the details.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:19,000 --> 00:02:23,000
|
| 143 |
+
In this example, we are going to have TV, radio and remote control.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:24,000 --> 00:02:30,000
|
| 147 |
+
Remote control may control both TV and radio, unlike all other previous examples.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:30,000 --> 00:02:33,000
|
| 151 |
+
Let me start this one from the client code.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:33,000 --> 00:02:37,000
|
| 155 |
+
I'm running this demo file explorer console output.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:37,000 --> 00:02:38,000
|
| 159 |
+
Together with you.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:38,000 --> 00:02:45,000
|
| 163 |
+
We have this device, Masset, that performs same operations with different remote implementations separately
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:45,000 --> 00:02:47,000
|
| 167 |
+
on TV and radio.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:02:47,000 --> 00:02:50,000
|
| 171 |
+
I call this massive and positive Zephyrs.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:02:51,000 --> 00:02:55,000
|
| 175 |
+
We have some basic remote that can only churn our device on.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:02:55,000 --> 00:02:58,000
|
| 179 |
+
And this is exactly what we did here.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:02:58,000 --> 00:03:06,000
|
| 183 |
+
We created our basic remote object and passed that our TV object and woke up our mast here and print
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:06,000 --> 00:03:06,000
|
| 187 |
+
status to.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:07,000 --> 00:03:09,000
|
| 191 |
+
So let's see what we have here.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:10,000 --> 00:03:16,000
|
| 195 |
+
We have indications that this is tasked with the basic remote and notifications that we have pressed.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:16,000 --> 00:03:17,000
|
| 199 |
+
Pobre Targo.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:18,000 --> 00:03:25,000
|
| 203 |
+
After that, I call matters that all devices in my example have been status Masvidal and we have status
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:25,000 --> 00:03:30,000
|
| 207 |
+
printed here and we see information about current volume and current channel rate.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:31,000 --> 00:03:38,000
|
| 211 |
+
What we can do next imagines that the next day we needed to improve our behavior and the way we interact
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:38,000 --> 00:03:41,000
|
| 215 |
+
with our device and change its state.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:41,000 --> 00:03:48,000
|
| 219 |
+
Now we need to be able to use the device and what have to do I have options is to adjust my existing
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:48,000 --> 00:03:49,000
|
| 223 |
+
remote control.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:50,000 --> 00:03:54,000
|
| 227 |
+
I'll get benefits from breach button and separation of obstruction and implementation.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:03:55,000 --> 00:04:03,000
|
| 231 |
+
So I have advanced remote object and I perform the same operation power Marsters invoked first and advanced
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:03,000 --> 00:04:05,000
|
| 235 |
+
remote that has such behavior as viewed.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:06,000 --> 00:04:08,000
|
| 239 |
+
After that I bring you my status to console.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:09,000 --> 00:04:10,000
|
| 243 |
+
And what do we have here now?
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:11,000 --> 00:04:14,000
|
| 247 |
+
We have the same TV, but this time it is disabled.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:15,000 --> 00:04:15,000
|
| 251 |
+
Why?
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:16,000 --> 00:04:22,000
|
| 255 |
+
Because Power Tuggle has been plagued second time and the state of the TV is changed.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:22,000 --> 00:04:29,000
|
| 259 |
+
This time it is turned off and we have volume of zero because we muted our TV.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:29,000 --> 00:04:30,000
|
| 263 |
+
Is that clear?
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:31,000 --> 00:04:36,000
|
| 267 |
+
You can see how I improved my remote control without touching my TV at all.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:37,000 --> 00:04:39,000
|
| 271 |
+
We have pretty similar story with the radio.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:39,000 --> 00:04:41,000
|
| 275 |
+
Renea is just another device.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:41,000 --> 00:04:41,000
|
| 279 |
+
Correct?
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:42,000 --> 00:04:48,000
|
| 283 |
+
And we can apply the same behavior to the radio at the beginning and you can see the demo of the basic
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:04:48,000 --> 00:04:49,000
|
| 287 |
+
remote object.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:04:49,000 --> 00:04:55,000
|
| 291 |
+
And afterwards we mute radio and you can see we have muted radio that is turned off.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:04:55,000 --> 00:05:01,000
|
| 295 |
+
And now is the most interesting part, how all of this is implemented now when you know how everything
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:01,000 --> 00:05:02,000
|
| 299 |
+
is broken here.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:03,000 --> 00:05:10,000
|
| 303 |
+
Dive deeper into details, we have device interface and implementation in the form of TV and radio,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:10,000 --> 00:05:15,000
|
| 307 |
+
each device may perform all actions that are listed in its interface.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:16,000 --> 00:05:17,000
|
| 311 |
+
Hope that there are not questions here.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:18,000 --> 00:05:22,000
|
| 315 |
+
The next interface that we have here is a remote interface.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:22,000 --> 00:05:28,000
|
| 319 |
+
This is an interface that describes all possible actions that remote may do.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:28,000 --> 00:05:32,000
|
| 323 |
+
We have basic remote like you saw and implements this interface.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:33,000 --> 00:05:38,000
|
| 327 |
+
And in case we need additional behavior, we have advanced remote that just extends the basic remote.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:39,000 --> 00:05:41,000
|
| 331 |
+
Pay attention to one important thing here.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:05:41,000 --> 00:05:47,000
|
| 335 |
+
Most basic remote and advanced remote don't have constructor without arguments.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:05:47,000 --> 00:05:51,000
|
| 339 |
+
All of them takes abstraction as an argument to work with it.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:05:51,000 --> 00:05:55,000
|
| 343 |
+
So each remote takes some device during the instantiation.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:05:56,000 --> 00:05:59,000
|
| 347 |
+
You can't create remote without device in this case.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:05:59,000 --> 00:06:04,000
|
| 351 |
+
And once the remote control has device, it changes its status.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:04,000 --> 00:06:10,000
|
| 355 |
+
And by the way, here is mute in advanced remote IT pricelock to console.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:10,000 --> 00:06:14,000
|
| 359 |
+
That message has been invoked and it changes volume on the device.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:15,000 --> 00:06:16,000
|
| 363 |
+
Does it make sense?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:16,000 --> 00:06:17,000
|
| 367 |
+
In this example?
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:17,000 --> 00:06:24,000
|
| 371 |
+
Our remote controls serve as an abstraction and our devices as implementation remote has a reference
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:24,000 --> 00:06:28,000
|
| 375 |
+
to device and the remote manages the specific device.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:28,000 --> 00:06:34,000
|
| 379 |
+
You can improve remote controls independently without necessarily updating of devices.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:34,000 --> 00:06:39,000
|
| 383 |
+
Can you understand now how all these types are connected between each other anyway?
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:06:39,000 --> 00:06:45,000
|
| 387 |
+
In case you have any questions, do not hesitate to write them in a section of this course.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:06:45,000 --> 00:06:51,000
|
| 391 |
+
And right now let's create a checklist that we need to follow during the implementation of each partner
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:06:52,000 --> 00:06:55,000
|
| 395 |
+
to implement breach button, follow next steps.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:06:55,000 --> 00:07:01,000
|
| 399 |
+
Define whether you have two Iraqis that can be improved and enhanced independently.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:01,000 --> 00:07:06,000
|
| 403 |
+
If yes, then split them into Iraq of abstractions and implementations.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:07,000 --> 00:07:10,000
|
| 407 |
+
Think about operations that would be needed to your client.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:11,000 --> 00:07:14,000
|
| 411 |
+
Describe these operations in abstraction class.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:14,000 --> 00:07:21,000
|
| 415 |
+
If you need new operations, great new abstraction, class designs, a separation of concerns.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:21,000 --> 00:07:25,000
|
| 419 |
+
What is abstraction and what is implementation of behavior?
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:25,000 --> 00:07:32,000
|
| 423 |
+
Great concrete classes of your domain type and behavior as a reference to the implementation to the
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:32,000 --> 00:07:39,000
|
| 427 |
+
class of the abstraction zephyrs exactly how we allowed to pass the words into the constructor to apply
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:39,000 --> 00:07:41,000
|
| 431 |
+
additional behavior in our example.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:42,000 --> 00:07:45,000
|
| 435 |
+
Then we get close to the target object at runtime.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:07:45,000 --> 00:07:50,000
|
| 439 |
+
These are steps that we passed to implement Bridgepoint from our example.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:07:50,000 --> 00:07:51,000
|
| 443 |
+
Hope it makes sense.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:07:52,000 --> 00:07:53,000
|
| 447 |
+
Let's continue.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:07:53,000 --> 00:07:57,000
|
| 451 |
+
And the next point that we are going to learn is a flyweight.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:07:57,000 --> 00:08:04,000
|
| 455 |
+
This is a program that allows us to aggregate a big number of objects by sharing the state between objects
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:04,000 --> 00:08:09,000
|
| 459 |
+
to not store the duplicated state and the same data in each object.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:09,000 --> 00:08:11,000
|
| 463 |
+
To explain it in simple words.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:12,000 --> 00:08:15,000
|
| 467 |
+
Imagine the next case, your development video.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:15,000 --> 00:08:22,000
|
| 471 |
+
Again, that would be GTA and you decide to blow up hundreds of cars that drives on the highway and
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:22,000 --> 00:08:24,000
|
| 475 |
+
issued them with a gun.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:24,000 --> 00:08:31,000
|
| 479 |
+
And you know that you already spent thousands of bullets and now your game crashed and closed after
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:31,000 --> 00:08:32,000
|
| 483 |
+
and used to gain locks.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:32,000 --> 00:08:38,000
|
| 487 |
+
You understand that there is not enough of RAM on your computer to store information about all bullets
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:08:38,000 --> 00:08:40,000
|
| 491 |
+
and all cars that you blew up.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:08:41,000 --> 00:08:48,000
|
| 495 |
+
Indeed, why should you store information about simulcasts and all bullets if are the same, that would
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:08:48,000 --> 00:08:50,000
|
| 499 |
+
allow you to save huge amount of memory?
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:08:50,000 --> 00:08:53,000
|
| 503 |
+
That is exactly the reason why we need to use flyways.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:08:53,000 --> 00:08:59,000
|
| 507 |
+
Sometimes, for example, each element should have different and common qualities.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:08:59,000 --> 00:09:05,000
|
| 511 |
+
For example, each car would have different color, but colors may be the same for many different objects.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:06,000 --> 00:09:10,000
|
| 515 |
+
That's why there is no need to store each color separately for each car.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:11,000 --> 00:09:14,000
|
| 519 |
+
Moreover, body of some cars also similar.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:14,000 --> 00:09:20,000
|
| 523 |
+
That's why you don't need to store dozens of the same 3D images of the same car.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:20,000 --> 00:09:24,000
|
| 527 |
+
But each car should have different coordinates in your virtual space.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:25,000 --> 00:09:29,000
|
| 531 |
+
That's what will be unique for each car and should be stored.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:29,000 --> 00:09:36,000
|
| 535 |
+
But we already saved a lot of the space because coordinates don't take as much space in RAM as cardboard
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:36,000 --> 00:09:43,000
|
| 539 |
+
images and colors information we can call something what has not changed in our state of the object
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:44,000 --> 00:09:46,000
|
| 543 |
+
and some state that is changed.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:09:46,000 --> 00:09:53,000
|
| 547 |
+
Or to state, for example, color and body type of the car in our video game is constant for each car
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:09:53,000 --> 00:09:56,000
|
| 551 |
+
and can be considered as in their state.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:09:56,000 --> 00:10:02,000
|
| 555 |
+
Coordinates of the car in the space is something what is unique and specific for each car.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:02,000 --> 00:10:03,000
|
| 559 |
+
And will be different.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:04,000 --> 00:10:11,000
|
| 563 |
+
That is called border state and now you can easily understand the main idea of a five wait partner.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:11,000 --> 00:10:19,000
|
| 567 |
+
The main idea of a five week program is to store on the interstate and pass border state as arguments
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:19,000 --> 00:10:21,000
|
| 571 |
+
when needed following this approach.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:21,000 --> 00:10:28,000
|
| 575 |
+
We have significantly lower number of objects and we can use the same objects with different order state
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:28,000 --> 00:10:30,000
|
| 579 |
+
to reproduce the state of different objects.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:31,000 --> 00:10:35,000
|
| 583 |
+
In this case, you can reuse the same objects in different contexts.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:35,000 --> 00:10:36,000
|
| 587 |
+
Does it make sense now?
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:10:37,000 --> 00:10:42,000
|
| 591 |
+
And flyweight partners should give us an answer where to store this order state.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:10:42,000 --> 00:10:45,000
|
| 595 |
+
And you can see different implementations in real life.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:10:46,000 --> 00:10:52,000
|
| 599 |
+
Often the state is stored in some container object, sometimes even in global context.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:10:52,000 --> 00:10:58,000
|
| 603 |
+
In this particular case, we have to store or a state map with the references to the real objects.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:10:59,000 --> 00:11:06,000
|
| 607 |
+
To simplify interaction, we can even create a factory of a flyways, for example, some factory masset
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:06,000 --> 00:11:09,000
|
| 611 |
+
that takes arguments and returns.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:09,000 --> 00:11:10,000
|
| 615 |
+
You ready to use object?
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:11,000 --> 00:11:17,000
|
| 619 |
+
And if you didn't skip the lesson about gradational points, namely about factory Macit now when you
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:17,000 --> 00:11:23,000
|
| 623 |
+
understood what flyweight pardon is, at least on the high level, let me show you an example, because
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:23,000 --> 00:11:27,000
|
| 627 |
+
with real code, it will be easier for you to get the details in.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:27,000 --> 00:11:31,000
|
| 631 |
+
Our example will create a force that consists from one million trees.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:31,000 --> 00:11:35,000
|
| 635 |
+
Each tree should be a separate object that contains info about each state.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:11:36,000 --> 00:11:42,000
|
| 639 |
+
Creating the forest with huge amount of trees will take a lot of space, but also a lot of trees share
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:11:42,000 --> 00:11:45,000
|
| 643 |
+
in the same state, same color name.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:11:46,000 --> 00:11:52,000
|
| 647 |
+
That's where flyweight Partan come into play will separate either and order state.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:11:52,000 --> 00:11:58,000
|
| 651 |
+
We create multiple objects of tree type class that will cache common information.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:11:59,000 --> 00:12:00,000
|
| 655 |
+
Let me show you this time.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:00,000 --> 00:12:02,000
|
| 659 |
+
Here is tree type class.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:02,000 --> 00:12:06,000
|
| 663 |
+
It has such fields as name color and as a tree data.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:07,000 --> 00:12:13,000
|
| 667 |
+
And instead of having Meenan objects of tree type, we can reduce our fly objects.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:13,000 --> 00:12:15,000
|
| 671 |
+
Let me show you the tree type.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:15,000 --> 00:12:19,000
|
| 675 |
+
You can see that each tree will have unique coordinates.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:19,000 --> 00:12:26,000
|
| 679 |
+
Matri objects also will have the reference to some common information that is shared in tree type object.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:26,000 --> 00:12:30,000
|
| 683 |
+
And you can't create tree object without the tree type.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:30,000 --> 00:12:37,000
|
| 687 |
+
Pay attention to this constructor what to do in case we need to get some tree type for such cases.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:37,000 --> 00:12:40,000
|
| 691 |
+
We have tree type factory in this factory.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:12:40,000 --> 00:12:47,000
|
| 695 |
+
We have a map that stores only one object mapped three key and we use tree name as a key.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:12:47,000 --> 00:12:54,000
|
| 699 |
+
That's why we have only one object mapped to one tree name and then static methods that allows us to
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:12:54,000 --> 00:12:55,000
|
| 703 |
+
get tree type.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:12:55,000 --> 00:12:57,000
|
| 707 |
+
We can request tree type.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:12:58,000 --> 00:13:01,000
|
| 711 |
+
I use multiple arguments to get the tree type that I need.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:02,000 --> 00:13:03,000
|
| 715 |
+
At the beginning.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:03,000 --> 00:13:10,000
|
| 719 |
+
I check whether I already have objects associated with such tree name and if no, then I create one
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:10,000 --> 00:13:12,000
|
| 723 |
+
and put in my map.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:12,000 --> 00:13:13,000
|
| 727 |
+
Is it there?
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:13,000 --> 00:13:16,000
|
| 731 |
+
Now let's look at the forest object.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:16,000 --> 00:13:23,000
|
| 735 |
+
In first object I have Masad plant a tree, I pass information and burn the tree that I want to plant
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:24,000 --> 00:13:27,000
|
| 739 |
+
and the first thing that I do, I want to get my tree type.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:28,000 --> 00:13:35,000
|
| 743 |
+
After that I create a tree object with a tree type and after that I add this tree to this list.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:13:36,000 --> 00:13:43,000
|
| 747 |
+
Can you see this and understand that storing some data entry type object allows us to share some properties
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:13:43,000 --> 00:13:46,000
|
| 751 |
+
and some state between multiple tree objects?
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:13:46,000 --> 00:13:51,000
|
| 755 |
+
Yes, tree is a separate object and yes, it has unique values.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:13:52,000 --> 00:13:59,000
|
| 759 |
+
But flyweight Porten allow this to save relatively a lot of memory by sharing some state between different
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:13:59,000 --> 00:13:59,000
|
| 763 |
+
objects.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:00,000 --> 00:14:01,000
|
| 767 |
+
Would you like to look at the client code?
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:02,000 --> 00:14:03,000
|
| 771 |
+
Let's do that.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:04,000 --> 00:14:05,000
|
| 775 |
+
This is our demo file.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:06,000 --> 00:14:11,000
|
| 779 |
+
In my example, I have only two types of trees, some oak and auton oak.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:12,000 --> 00:14:15,000
|
| 783 |
+
Obviously these trees will have different colors.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:16,000 --> 00:14:19,000
|
| 787 |
+
I generate coordinates randomly with this method.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:19,000 --> 00:14:22,000
|
| 791 |
+
I will not focus on the logic of the method.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:23,000 --> 00:14:30,000
|
| 795 |
+
After I planted one million trees, I set search for my window and make it visible in parallel.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:14:30,000 --> 00:14:33,000
|
| 799 |
+
I print statistics to consult in statistics.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:14:33,000 --> 00:14:40,000
|
| 803 |
+
You may find information about memory usage and to show you how it works, let me run this program.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:14:41,000 --> 00:14:48,000
|
| 807 |
+
This is done with old fashioned Java stack for desktop applications, but it doesn't matter for understanding
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:14:48,000 --> 00:14:49,000
|
| 811 |
+
of lightweight parren.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:14:50,000 --> 00:14:53,000
|
| 815 |
+
You see the trees are planted on the screen.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:14:53,000 --> 00:14:57,000
|
| 819 |
+
Let's now check console output to check the statistics.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:14:57,000 --> 00:15:02,000
|
| 823 |
+
By my approximate calculations, we saved approximately certain megabytes.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:02,000 --> 00:15:09,000
|
| 827 |
+
One million trees, OK, now you clearly understand how flyweight pardon works and what is needed to
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:09,000 --> 00:15:10,000
|
| 831 |
+
be done to implement it.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:11,000 --> 00:15:16,000
|
| 835 |
+
Let's now create checklists to implement this plan to implement flyweight point.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:17,000 --> 00:15:18,000
|
| 839 |
+
We need to follow next steps.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:19,000 --> 00:15:26,000
|
| 843 |
+
The first thing we need to do is to split the state of our object into groups in and order state.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:26,000 --> 00:15:33,000
|
| 847 |
+
We should clearly understand what state is the same across all objects and may be shared and what state
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:15:33,000 --> 00:15:41,000
|
| 851 |
+
is unique created that where Constance feels will be initialized as a construct to make sure that the
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:15:41,000 --> 00:15:42,000
|
| 855 |
+
state may be passed.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:15:42,000 --> 00:15:49,000
|
| 859 |
+
As message arguments create factories that will Kasher state and will return already created objects
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:15:50,000 --> 00:15:58,000
|
| 863 |
+
clients should request object to a specific state, but not create it directly to restore order, state
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:15:58,000 --> 00:16:05,000
|
| 867 |
+
or generate ZOS and Puzzle's as an argument flyway that ensures the list of actions added to implement
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:05,000 --> 00:16:06,000
|
| 871 |
+
this example.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:07,000 --> 00:16:08,000
|
| 875 |
+
Hope this will help you.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:09,000 --> 00:16:10,000
|
| 879 |
+
And we have the last but not least.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:11,000 --> 00:16:14,000
|
| 883 |
+
And for today it is called composite and few words.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:14,000 --> 00:16:21,000
|
| 887 |
+
Composite allows us to group objects in tree like structure and interact with objects as a single one.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:22,000 --> 00:16:28,000
|
| 891 |
+
Applying this pardon makes sense only in cases when all your objects may be structured in three like
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:28,000 --> 00:16:29,000
|
| 895 |
+
organization.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:30,000 --> 00:16:36,000
|
| 899 |
+
For example, imagine that you have online store and use seven different products and also provide service
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:16:36,000 --> 00:16:38,000
|
| 903 |
+
of back and products deliver.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:16:38,000 --> 00:16:43,000
|
| 907 |
+
Some products are wrapped in the box that customer paid for.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:16:43,000 --> 00:16:46,000
|
| 911 |
+
So each box may contain few products.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:16:46,000 --> 00:16:50,000
|
| 915 |
+
Box may contain other smaller boxes that contain products too.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:16:51,000 --> 00:16:55,000
|
| 919 |
+
And imagine that you need to calculate the price of the whole order.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:16:55,000 --> 00:17:02,000
|
| 923 |
+
The first solutions is probably you might think of is to iterate over each box, extract it and iterate
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:02,000 --> 00:17:07,000
|
| 927 |
+
over each product inside and some of the price did I guess.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:07,000 --> 00:17:09,000
|
| 931 |
+
But this task might be challenging.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:09,000 --> 00:17:16,000
|
| 935 |
+
You don't always know how much less you have on each iteration and structure of the boxes composite
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:16,000 --> 00:17:23,000
|
| 939 |
+
part and in this case suggest that's to take all boxes and product as a single object and get total
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:23,000 --> 00:17:26,000
|
| 943 |
+
price at once for the client.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:17:26,000 --> 00:17:30,000
|
| 947 |
+
In this case, there is no need to know anything about internal structure.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:17:30,000 --> 00:17:35,000
|
| 951 |
+
But probably the most interesting thing here is how all this is implemented.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:17:36,000 --> 00:17:38,000
|
| 955 |
+
I suggest to investigate the code example.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:17:38,000 --> 00:17:44,000
|
| 959 |
+
I'm sure that the real example will bring some clarity, understanding of this point.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:17:44,000 --> 00:17:47,000
|
| 963 |
+
Imagine that we are developing some UI.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:17:47,000 --> 00:17:53,000
|
| 967 |
+
We have common interface for all shapes in our example here, shape interface this.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:17:53,000 --> 00:17:57,000
|
| 971 |
+
This is all behaviors that should be implemented by each shape.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:17:57,000 --> 00:18:05,000
|
| 975 |
+
We have abstract class based shape that implement some masses and can create shape implementations extends
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:05,000 --> 00:18:06,000
|
| 979 |
+
this abstract class.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:07,000 --> 00:18:11,000
|
| 983 |
+
We have circle, compound, shape, note and rectangle.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:11,000 --> 00:18:18,000
|
| 987 |
+
Nothing special in these classes besides compound shape, class, these type aggregates least of other
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:18:18,000 --> 00:18:21,000
|
| 991 |
+
shapes and works with a group of shapes inside.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:18:22,000 --> 00:18:29,000
|
| 995 |
+
The object of this type may contain multiple shapes and containers with shapes containing with shapes,
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:18:29,000 --> 00:18:32,000
|
| 999 |
+
implements the same methods as a shape.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:18:33,000 --> 00:18:40,000
|
| 1003 |
+
But instead of direct action, it passes the action to the shapes inside using recursion after that
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:18:40,000 --> 00:18:49,000
|
| 1007 |
+
contain some the results of our code interact with the specific interface and even don't know whether
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:18:49,000 --> 00:18:51,000
|
| 1011 |
+
we have simple shape or group of shapes.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:18:51,000 --> 00:18:54,000
|
| 1015 |
+
We have also image added the class here.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:18:54,000 --> 00:18:59,000
|
| 1019 |
+
But this is only specific for our demo and not specific to the composite.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:18:59,000 --> 00:19:03,000
|
| 1023 |
+
Part of this class helps us to visualize the shapes in the window.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:04,000 --> 00:19:08,000
|
| 1027 |
+
Now let's open our democracy and see what we have here.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:08,000 --> 00:19:16,000
|
| 1031 |
+
I create Image editor to upload the different shapes and you can see that I uploaded circle here and
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:16,000 --> 00:19:17,000
|
| 1035 |
+
to compound shapes.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:19:18,000 --> 00:19:20,000
|
| 1039 |
+
So it consists inside from different shapes.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:19:21,000 --> 00:19:24,000
|
| 1043 |
+
There's an interesting scene also inside that image added.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:19:24,000 --> 00:19:29,000
|
| 1047 |
+
All shapes are added in one variable of type compound shape.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:19:29,000 --> 00:19:37,000
|
| 1051 |
+
And if you would look on these masses and in particular on MassArt of inner class editor canvas, you
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:19:37,000 --> 00:19:43,000
|
| 1055 |
+
would notice that there are no any loops here and we interact with all shapes as a single object.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:19:44,000 --> 00:19:48,000
|
| 1059 |
+
You see just Kullen, one Masset and no loops.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:19:48,000 --> 00:19:55,000
|
| 1063 |
+
And for energy canvas as a client, it doesn't matter whether there is a group of objects or a single
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:19:55,000 --> 00:19:56,000
|
| 1067 |
+
object behind the reference.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:19:57,000 --> 00:20:01,000
|
| 1071 |
+
That is exactly the reason why we need to apply composites partly for and.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:02,000 --> 00:20:08,000
|
| 1075 |
+
For the sake of the drama, let me run them across and here you can see different shapes and group of
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:08,000 --> 00:20:09,000
|
| 1079 |
+
shapes.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:10,000 --> 00:20:14,000
|
| 1083 |
+
Now let's review the checklist to implement the composite pardon.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:14,000 --> 00:20:15,000
|
| 1087 |
+
Follow next steps.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:16,000 --> 00:20:20,000
|
| 1091 |
+
Make sure that you can apply a tree like structure for your components.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:20,000 --> 00:20:27,000
|
| 1095 |
+
Create a unified interface that will combine operations on the group of objects and on the single object.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:27,000 --> 00:20:34,000
|
| 1099 |
+
Create a class of single object grade class for group of objects that implements the same unified interface
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:20:35,000 --> 00:20:40,000
|
| 1103 |
+
and operations to add and remove components into the container.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:20:40,000 --> 00:20:41,000
|
| 1107 |
+
That's it.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:20:41,000 --> 00:20:47,000
|
| 1111 |
+
Now you have the interface that allows you to interact with a group of objects as a single one.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:20:48,000 --> 00:20:49,000
|
| 1115 |
+
Now you know composites.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:20:49,000 --> 00:20:50,000
|
| 1119 |
+
Pardon?
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:20:50,000 --> 00:20:54,000
|
| 1123 |
+
Let's recap what we have learned to date in this lesson.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:20:54,000 --> 00:20:56,000
|
| 1127 |
+
Learned three structural patterns.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:20:56,000 --> 00:20:59,000
|
| 1131 |
+
They are bridge, lightweight and composite.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:21:00,000 --> 00:21:02,000
|
| 1135 |
+
That's it for this lesson.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:02,000 --> 00:21:03,000
|
| 1139 |
+
Thanks a lot for your attention.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:04,000 --> 00:21:06,000
|
| 1143 |
+
Have a great day and see you in the next lesson.
|
| 1144 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/005 Behevioral Patterns, p.1_en.srt
ADDED
|
@@ -0,0 +1,1688 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:12,000
|
| 7 |
+
In this lesson, we start learning of golf behavioral patterns, we already performed an overview of
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:19,000
|
| 11 |
+
behavioral patterns and I hope you remember that the 11 of them and definitely we won't have time to
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:22,000
|
| 15 |
+
make an area with example for all of them in this lesson.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:28,000
|
| 19 |
+
But at least we'll start we'll start from the most popular behavioral patterns, in my opinion.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:34,000
|
| 23 |
+
And that's why in this last world alone, with your strategy pattern, common pattern, template, Masad
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:34,000 --> 00:00:41,000
|
| 27 |
+
partner, iterator and chain of responsibility padam, you can find good examples in attachments to
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:41,000 --> 00:00:46,000
|
| 31 |
+
this lesson will go over these examples as we will talk through each part.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:46,000 --> 00:00:49,000
|
| 35 |
+
Let's start and we start from strategy.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:49,000 --> 00:00:53,000
|
| 39 |
+
Parren, let me explain your strategy in simple words.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:54,000 --> 00:00:57,000
|
| 43 |
+
Imagine that you know how something is needed to be done.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:57,000 --> 00:01:03,000
|
| 47 |
+
For example, you know how certain needs to be done or to know how filtering needs to be done.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:04,000 --> 00:01:07,000
|
| 51 |
+
Or you have information how car engine should be started.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:08,000 --> 00:01:10,000
|
| 55 |
+
Now you can describe the logic in the code.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:10,000 --> 00:01:11,000
|
| 59 |
+
Correct.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:12,000 --> 00:01:16,000
|
| 63 |
+
So you encapsulated the way how something should be done in one class.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:17,000 --> 00:01:19,000
|
| 67 |
+
That is exactly what strategy partner is about.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:20,000 --> 00:01:25,000
|
| 71 |
+
And now imagine that you know that you need to search users, but you can search by first name and by
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:25,000 --> 00:01:26,000
|
| 75 |
+
last name.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:26,000 --> 00:01:29,000
|
| 79 |
+
You know, that car engine should be started.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:29,000 --> 00:01:33,000
|
| 83 |
+
But the way how electric engine and petrol engine is started are different.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:34,000 --> 00:01:35,000
|
| 87 |
+
What do you need now?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:35,000 --> 00:01:42,000
|
| 91 |
+
You need an abstraction so you can create an absolute interface and have multiple implementations that
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:42,000 --> 00:01:44,000
|
| 95 |
+
will describe how something should be done.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:45,000 --> 00:01:46,000
|
| 99 |
+
Does it make sense?
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:46,000 --> 00:01:53,000
|
| 103 |
+
Strategic partner commands us to define a group of similar algorithms that are changing or expanding.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:53,000 --> 00:01:58,000
|
| 107 |
+
For example, a group of sorting algorithms, group of filtering algorithms, etc..
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:59,000 --> 00:02:06,000
|
| 111 |
+
And with this pardon, you don't need to describe the logic inside the client classes because you encapsulated
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:06,000 --> 00:02:09,000
|
| 115 |
+
the behavior and strategy that can be used across your app.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:10,000 --> 00:02:16,000
|
| 119 |
+
This should increase called reusability to help this clear for you why we need strategy.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:16,000 --> 00:02:22,000
|
| 123 |
+
And sometimes let's look at example to understand the details of implementation.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:22,000 --> 00:02:29,000
|
| 127 |
+
Imagine that we have multiple compression algorithms and I decide to group all compression algorithms
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:29,000 --> 00:02:33,000
|
| 131 |
+
and the one single abstraction that is called compression strategy.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:34,000 --> 00:02:38,000
|
| 135 |
+
You can see that compression strategy is a functional interface.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:38,000 --> 00:02:40,000
|
| 139 |
+
What is a functional interface in Java?
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:41,000 --> 00:02:45,000
|
| 143 |
+
You can learn from functional programming section of my Java course.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:45,000 --> 00:02:53,000
|
| 147 |
+
You can see that I have only one method here compress files that takes list of files Zellous abstractions
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:53,000 --> 00:02:56,000
|
| 151 |
+
that will unite all algorithms of such type.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:57,000 --> 00:03:05,000
|
| 155 |
+
And I have recompression strategy class that implements this method and zeeb compression strategy that
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:05,000 --> 00:03:06,000
|
| 159 |
+
implements this method.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:06,000 --> 00:03:10,000
|
| 163 |
+
Do for the sake of the demo I just text to console here.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:11,000 --> 00:03:17,000
|
| 167 |
+
Having this kind of abstraction, you can include it and use it in different clients.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:17,000 --> 00:03:24,000
|
| 171 |
+
For example, you may have some kind of class where you want to use compression strategy and also you
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:24,000 --> 00:03:27,000
|
| 175 |
+
want to be able to substitute compression algorithm on the fly.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:28,000 --> 00:03:30,000
|
| 179 |
+
Here you can see compression context class.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:31,000 --> 00:03:38,000
|
| 183 |
+
We can declare compression strategy field right now here to set or change the compression strategy on
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:38,000 --> 00:03:38,000
|
| 187 |
+
the fly.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:38,000 --> 00:03:45,000
|
| 191 |
+
We have the scatter method here and the main method of compression context would be create archive that
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:45,000 --> 00:03:53,000
|
| 195 |
+
takes listo files as an argument and where we can do some preparation actions, actually compress files
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:53,000 --> 00:03:59,000
|
| 199 |
+
and perform some actions after that one and being able change in compression algorithms.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:00,000 --> 00:04:06,000
|
| 203 |
+
You can set an implementation of compression strategy and it will be used to compress files here.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:06,000 --> 00:04:07,000
|
| 207 |
+
Does it make sense?
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:08,000 --> 00:04:14,000
|
| 211 |
+
Another version of strategy Partons usage espersen strategy as Masset argument.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:14,000 --> 00:04:20,000
|
| 215 |
+
This is pretty convenient saying let me show you how to work with this compression context in my demo
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:20,000 --> 00:04:21,000
|
| 219 |
+
file.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:21,000 --> 00:04:25,000
|
| 223 |
+
First of all, I create an object of a compression context.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:25,000 --> 00:04:32,000
|
| 227 |
+
And by the way, you can pass compression strategy is a work constructor of a certain Macit Z.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:32,000 --> 00:04:33,000
|
| 231 |
+
Yes, similar.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:33,000 --> 00:04:35,000
|
| 235 |
+
You pass strategy from outside.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:36,000 --> 00:04:43,000
|
| 239 |
+
Imagine that I have the list of files and now I call create archive masset of my compression context
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:43,000 --> 00:04:45,000
|
| 243 |
+
and pass list of files there.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:46,000 --> 00:04:53,000
|
| 247 |
+
And now let me show you another way of passing strategy to the compression context in Java.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:53,000 --> 00:05:00,000
|
| 251 |
+
If we have functional interface, that means that we can describe interface with lambda expression and
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:00,000 --> 00:05:02,000
|
| 255 |
+
that's why you can pass Lambda to our.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:02,000 --> 00:05:11,000
|
| 259 |
+
Overlord masses here I call creator archive Masset past list of files and lambda expression of my compression
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:11,000 --> 00:05:18,000
|
| 263 |
+
strategy that technically also prints text to console and now overloaded MassArt is called Take into
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:18,000 --> 00:05:22,000
|
| 267 |
+
account compression strategy is a functional interface.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:22,000 --> 00:05:27,000
|
| 271 |
+
I also may pass MASSATA reference that will meet the requirements of the interface.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:28,000 --> 00:05:35,000
|
| 275 |
+
For example, here is a static method inside my demo class that also takes list of files and prints,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:35,000 --> 00:05:38,000
|
| 279 |
+
text to console, imitate compression.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:38,000 --> 00:05:44,000
|
| 283 |
+
If you are not familiar with MassArt references lambda expressions, check the functional programming
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:44,000 --> 00:05:45,000
|
| 287 |
+
section of my Java course.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:46,000 --> 00:05:52,000
|
| 291 |
+
But in this lesson, this example is more to show you how you can use strategy in real life.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:52,000 --> 00:05:57,000
|
| 295 |
+
And I am sure that you already used Strategy Partan and even didn't know about that.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:58,000 --> 00:06:00,000
|
| 299 |
+
There are no comparator interface.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:00,000 --> 00:06:03,000
|
| 303 |
+
That is pure example of strategy parren.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:03,000 --> 00:06:12,000
|
| 307 |
+
That's why I can call sort masset unleased object and pass lambda expression that because comparator
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:12,000 --> 00:06:13,000
|
| 311 |
+
is a functional interface too.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:14,000 --> 00:06:15,000
|
| 315 |
+
Is that clear.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:16,000 --> 00:06:21,000
|
| 319 |
+
You can press a pause for a minute and investigate the source code that is attached to this lesson.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:22,000 --> 00:06:26,000
|
| 323 |
+
In case of any questions, you're welcome to write a question in the Commons.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:27,000 --> 00:06:32,000
|
| 327 |
+
And once you are sure that everything is clear for you, let's review the checklist of strategy.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:32,000 --> 00:06:36,000
|
| 331 |
+
Parren to implement strategy partner follow next steps.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:36,000 --> 00:06:39,000
|
| 335 |
+
Identify group of algorithms in your app.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:40,000 --> 00:06:43,000
|
| 339 |
+
Create an interface for such a group of algorithms.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:44,000 --> 00:06:49,000
|
| 343 |
+
Create concrete classes that implements the interface and can create algorithms.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:49,000 --> 00:06:55,000
|
| 347 |
+
And you know that in Java language you can also use lambda expressions or method references because
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:55,000 --> 00:06:59,000
|
| 351 |
+
most likely your strategy interface will be a functional interface.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:00,000 --> 00:07:03,000
|
| 355 |
+
Use the strategy and client code wherever it is needed.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:04,000 --> 00:07:05,000
|
| 359 |
+
That Sitrick strategy parren.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:06,000 --> 00:07:08,000
|
| 363 |
+
Let's continue now.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:08,000 --> 00:07:11,000
|
| 367 |
+
Let's review the next part and its name is comment.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:11,000 --> 00:07:13,000
|
| 371 |
+
Parn Comments.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:13,000 --> 00:07:21,000
|
| 375 |
+
Partan describes how we can create an object from a request and actually we expect to get a lot of benefits
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:21,000 --> 00:07:21,000
|
| 379 |
+
from that.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:22,000 --> 00:07:26,000
|
| 383 |
+
Try to see what the benefits of having request as an object.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:27,000 --> 00:07:29,000
|
| 387 |
+
You can put request in the queue.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:29,000 --> 00:07:35,000
|
| 391 |
+
You can make the first call of a request you can and the operation if needed.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:35,000 --> 00:07:42,000
|
| 395 |
+
And others imagine that you developed a new keyboard and you create software to make sure that your
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:42,000 --> 00:07:44,000
|
| 399 |
+
keyboard works well with the computer.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:44,000 --> 00:07:49,000
|
| 403 |
+
And you should write code that will process event of pressing each key.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:49,000 --> 00:07:56,000
|
| 407 |
+
And imagine that you should store the code that process key button press somewhere and this code should
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:56,000 --> 00:07:56,000
|
| 411 |
+
work.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:56,000 --> 00:07:58,000
|
| 415 |
+
Only one button is clicked.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:59,000 --> 00:08:02,000
|
| 419 |
+
And also you have something else to consider.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:02,000 --> 00:08:10,000
|
| 423 |
+
Such operations as copy and paste, for example, may be performed with a keyboard and mouse with keyboard.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:10,000 --> 00:08:18,000
|
| 427 |
+
For example, when you press control who I see and control passively and with mouse you can do mouse,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:18,000 --> 00:08:18,000
|
| 431 |
+
right?
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:18,000 --> 00:08:21,000
|
| 435 |
+
Click and select is a copy or paste.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:22,000 --> 00:08:28,000
|
| 439 |
+
What you have to do, have this logic duplicated in two places or with the application to put logic
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:28,000 --> 00:08:31,000
|
| 443 |
+
of copying and pasting in glosses.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:31,000 --> 00:08:37,000
|
| 447 |
+
The solution would be to drop a request in a single object that is called command.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:37,000 --> 00:08:44,000
|
| 451 |
+
This object will contain information about what is needed to be done and command object may be aggregated,
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:44,000 --> 00:08:52,000
|
| 455 |
+
but any other object, no matter whether it is a keyboard or an operating system menu event, this request
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:52,000 --> 00:08:58,000
|
| 459 |
+
will be stored in one single object and will be invoked by a client when it is needed.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:58,000 --> 00:09:05,000
|
| 463 |
+
A group of related commands may be united under the common abstraction to let clients rely on abstraction
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:06,000 --> 00:09:08,000
|
| 467 |
+
but not on concrete implementations.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:09,000 --> 00:09:14,000
|
| 471 |
+
If you want to understand this problem better, let me share with your real life analogy.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:14,000 --> 00:09:20,000
|
| 475 |
+
You're at a restaurant and waiter come to you to check whether you're ready to make an order.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:20,000 --> 00:09:29,000
|
| 479 |
+
You order some food and after that waiter goes to the kitchen there, he passes your order in the process
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:29,000 --> 00:09:30,000
|
| 483 |
+
of cooking is started.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:31,000 --> 00:09:37,000
|
| 487 |
+
So you encapsulated your command in Waiter Object and waiter made your order happen.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:37,000 --> 00:09:39,000
|
| 491 |
+
In this example, your request.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:39,000 --> 00:09:44,000
|
| 495 |
+
The waiter is a command and cook is a receiver.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:44,000 --> 00:09:49,000
|
| 499 |
+
You are not in touch with Schoop directly and not going to the kitchen.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:49,000 --> 00:09:53,000
|
| 503 |
+
You are sitting in the chair and making an order as it makes sense.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:54,000 --> 00:09:57,000
|
| 507 |
+
Hope you grasp the idea of command power.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:58,000 --> 00:10:05,000
|
| 511 |
+
Let's now, which is a good example of this point in our example, we'll work with the light and commands
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:05,000 --> 00:10:09,000
|
| 515 |
+
to turn on and turn off the light from the remote control.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:09,000 --> 00:10:14,000
|
| 519 |
+
In this real life case, the program, such behavior, it is a good idea to use command.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:14,000 --> 00:10:15,000
|
| 523 |
+
Pardon?
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:15,000 --> 00:10:19,000
|
| 527 |
+
Let's start from the client code and we'll go from there.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:19,000 --> 00:10:22,000
|
| 531 |
+
Imagine that we have remote control.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:22,000 --> 00:10:24,000
|
| 535 |
+
That is a separate class.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:24,000 --> 00:10:26,000
|
| 539 |
+
Let me open it here.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:26,000 --> 00:10:30,000
|
| 543 |
+
You can see that remote control type aggregates command inside.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:31,000 --> 00:10:38,000
|
| 547 |
+
I can set command with this set of Masset and I can press the one button on my remote control to execute
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:38,000 --> 00:10:41,000
|
| 551 |
+
the behavior that is encapsulated in the command.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:42,000 --> 00:10:44,000
|
| 555 |
+
Let's look at the command interface.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:45,000 --> 00:10:49,000
|
| 559 |
+
This is an interface that declares only one Massett execute.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:50,000 --> 00:10:53,000
|
| 563 |
+
OK, now let's get back to our demo file.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:53,000 --> 00:10:55,000
|
| 567 |
+
Now we create light object.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:56,000 --> 00:11:03,000
|
| 571 |
+
This would be receiver object, the object that should expect some impact made by our command.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:03,000 --> 00:11:05,000
|
| 575 |
+
Let me open the close.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:05,000 --> 00:11:13,000
|
| 579 |
+
You can see that each state consists only from one field that reflects where the light is on or off
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:14,000 --> 00:11:16,000
|
| 583 |
+
and the mass of the change.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:16,000 --> 00:11:19,000
|
| 587 |
+
The state of this field switch on and switch off.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:20,000 --> 00:11:22,000
|
| 591 |
+
Let's get back to the demo file.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:23,000 --> 00:11:29,000
|
| 595 |
+
Now I create two commands command to turn light on and to turn light off.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:29,000 --> 00:11:34,000
|
| 599 |
+
I create object of light on command type and light of command.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:34,000 --> 00:11:43,000
|
| 603 |
+
Todd, let me open one of these because they're similar in this case, my command aggregates receiver
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:43,000 --> 00:11:43,000
|
| 607 |
+
object.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:44,000 --> 00:11:51,000
|
| 611 |
+
You can see I proselyte object as a constructor and initialize state of my command object.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:51,000 --> 00:11:54,000
|
| 615 |
+
This class implements command interface.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:54,000 --> 00:11:58,000
|
| 619 |
+
Thus it should provide us with execute Masset implementation.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:59,000 --> 00:12:02,000
|
| 623 |
+
And you can see here inside execute Masset.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:02,000 --> 00:12:08,000
|
| 627 |
+
I operate on light object basically that set in as a command.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:08,000 --> 00:12:15,000
|
| 631 |
+
The only thing that is different is that I could switch off Massett on the light object and that's it.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:16,000 --> 00:12:18,000
|
| 635 |
+
Now let's look how we work with these commands.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:19,000 --> 00:12:25,000
|
| 639 |
+
We are again in our demo file and looking around this file to explore console output together with you.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:26,000 --> 00:12:30,000
|
| 643 |
+
At first I said turn on command to my remote control.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:31,000 --> 00:12:37,000
|
| 647 |
+
Basically, that means when the user presses a button on the remote control, the lights on command
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:37,000 --> 00:12:38,000
|
| 651 |
+
will be executed.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:39,000 --> 00:12:43,000
|
| 655 |
+
And when I press the button on, my remote light is turned on.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:44,000 --> 00:12:50,000
|
| 659 |
+
After that, I set another command to my remote control and now when the user clicks the same button
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:50,000 --> 00:12:54,000
|
| 663 |
+
on the remote control, the light is turned off.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:54,000 --> 00:12:55,000
|
| 667 |
+
That's it.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:56,000 --> 00:12:56,000
|
| 671 |
+
Home.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:56,000 --> 00:12:57,000
|
| 675 |
+
That was the example.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:57,000 --> 00:13:01,000
|
| 679 |
+
It becomes clear how we'll use our command button in real life.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:02,000 --> 00:13:05,000
|
| 683 |
+
Let's create a checklist here.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:05,000 --> 00:13:13,000
|
| 687 |
+
Simple items to follow to implement the command button defines a common interface for commands and identify
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:13,000 --> 00:13:18,000
|
| 691 |
+
the command and to point create implementations of this interface.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:18,000 --> 00:13:22,000
|
| 695 |
+
Each command should stores a reference to the receiver object.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:23,000 --> 00:13:29,000
|
| 699 |
+
Also, command should store all necessary arguments to cost the receiver at command.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:30,000 --> 00:13:37,000
|
| 703 |
+
The request object is the one that sends the request invoke commands Masset when needed and pass all
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:37,000 --> 00:13:41,000
|
| 707 |
+
necessary arguments to interact with the receiver homes.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:41,000 --> 00:13:46,000
|
| 711 |
+
That this checklist will help you on implementation stage in your project.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:46,000 --> 00:13:47,000
|
| 715 |
+
Let's move on.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:48,000 --> 00:13:56,000
|
| 719 |
+
But before we move to the next portion, let's compare this to strategy and the command points, because
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:56,000 --> 00:14:00,000
|
| 723 |
+
my students always see a lot of similar things between these two points.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:00,000 --> 00:14:04,000
|
| 727 |
+
But still, I want to make sure that you see clear difference between them.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:05,000 --> 00:14:12,000
|
| 731 |
+
Typically, the command portion is used to make an object out of what needs to be done to take in the
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:12,000 --> 00:14:20,000
|
| 735 |
+
operation and its arguments and wrap them up in an object to be looked held from the center, remote
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:20,000 --> 00:14:22,000
|
| 739 |
+
site, etc..
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:22,000 --> 00:14:29,000
|
| 743 |
+
There will tend to be a large number of distinct command objects that pass through a given point in
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:29,000 --> 00:14:35,000
|
| 747 |
+
the system over time, and the command objects will hold varying parameters.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:35,000 --> 00:14:42,000
|
| 751 |
+
Describing the operation requested the strategy part and on the other hand, is used to specify how
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:42,000 --> 00:14:49,000
|
| 755 |
+
something should be done and blocks into a larger object or Massett to provide a specific algorithm.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:49,000 --> 00:14:53,000
|
| 759 |
+
A strategy for sorting might be Amersfoort.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:53,000 --> 00:15:00,000
|
| 763 |
+
Might be an insertion source or perhaps even something more complex, like only using my short if the
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:00,000 --> 00:15:04,000
|
| 767 |
+
list is larger than some minimum size, feel the difference.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:05,000 --> 00:15:12,000
|
| 771 |
+
The differences are in the use cases and it in practice and the intent behind each part.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:13,000 --> 00:15:13,000
|
| 775 |
+
Let's.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:13,000 --> 00:15:19,000
|
| 779 |
+
Learning behavioral patterns, I suggest, has to focus on the template Macit part.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:19,000 --> 00:15:27,000
|
| 783 |
+
Now this part allows us to define skeleton of the algorithms and let subclasses to decide the implementation
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:27,000 --> 00:15:30,000
|
| 787 |
+
of specific steps of this algorithm.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:30,000 --> 00:15:37,000
|
| 791 |
+
Subclasses may provide us with implementation of some steps of the common algorithm without changing
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:37,000 --> 00:15:38,000
|
| 795 |
+
the algorithm structure.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:39,000 --> 00:15:46,000
|
| 799 |
+
Imagine that you're dealing with a case of data mining and in your app your allow and user to upload
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:46,000 --> 00:15:49,000
|
| 803 |
+
Doc C suite and PDA files.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:49,000 --> 00:15:56,000
|
| 807 |
+
And once you've found that some steps are common in all cases, you always upload file to some temporary
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:56,000 --> 00:15:57,000
|
| 811 |
+
storage.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:57,000 --> 00:15:59,000
|
| 815 |
+
After that, you retrieve data from it.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:59,000 --> 00:16:03,000
|
| 819 |
+
After that, you pass this data and send to a database.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:04,000 --> 00:16:10,000
|
| 823 |
+
Basically, the algorithm of data processing is the same for different types of documents.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:10,000 --> 00:16:17,000
|
| 827 |
+
The only thing that is different is the way how data is retrieved from the files of different format.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:17,000 --> 00:16:25,000
|
| 831 |
+
That's why it might be a good idea to create a template that describes each step of this algorithm and
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:16:25,000 --> 00:16:28,000
|
| 835 |
+
that gives implementation to the common steps.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:28,000 --> 00:16:33,000
|
| 839 |
+
Instead of having this code duplicated and have specific classes, that implements one step in this
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:16:33,000 --> 00:16:34,000
|
| 843 |
+
algorithm.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:16:35,000 --> 00:16:38,000
|
| 847 |
+
Following this approach, you reduce code duplication.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:39,000 --> 00:16:42,000
|
| 851 |
+
I also can come up with an analogy from the real life.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:43,000 --> 00:16:46,000
|
| 855 |
+
Imagine that you have building a company that builds houses.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:47,000 --> 00:16:51,000
|
| 859 |
+
In all cases, you have the same steps to follow during house building.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:51,000 --> 00:16:58,000
|
| 863 |
+
You should agree on architecture, prepare basement, create walls, install doors and windows and so
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:58,000 --> 00:16:59,000
|
| 867 |
+
on and so forth.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:59,000 --> 00:17:05,000
|
| 871 |
+
The algorithm of house building is the same, but each step can be done differently.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:05,000 --> 00:17:11,000
|
| 875 |
+
Different doors may be installed of different sizes, different roof types and so on.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:11,000 --> 00:17:17,000
|
| 879 |
+
Let's now check the current example of this parliament to understand the details of this pardon.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:17,000 --> 00:17:23,000
|
| 883 |
+
In our example, we plan to create a template Masset for mobile app compilation template.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:17:23,000 --> 00:17:26,000
|
| 887 |
+
Marcet is located in Crus compiler class.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:17:26,000 --> 00:17:28,000
|
| 891 |
+
It is called Compile.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:17:29,000 --> 00:17:36,000
|
| 895 |
+
This algorithm consists of the next steps, collect all necessary sources for compilation, reserve
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:17:36,000 --> 00:17:42,000
|
| 899 |
+
some rame, compile sources to target archive and share compilation status.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:43,000 --> 00:17:50,000
|
| 903 |
+
We have also so-called Hoak Macit here cukes a special message that is not mandatory to override or
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:50,000 --> 00:17:56,000
|
| 907 |
+
implement, but they give additional opportunity for various algorithms to add some behavior.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:57,000 --> 00:18:02,000
|
| 911 |
+
As we go through the main steps of our algorithm, you can put these placeholders.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:18:02,000 --> 00:18:08,000
|
| 915 |
+
Mascot's in any place you think would be logical, reasonable for Skillern in the future.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:18:08,000 --> 00:18:14,000
|
| 919 |
+
And some of these steps are common for all compilers and some of them are not.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:18:14,000 --> 00:18:20,000
|
| 923 |
+
For example, reserving RAM and printing status is the same step for different compilers.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:18:20,000 --> 00:18:25,000
|
| 927 |
+
And you can see implementation of this method here in this abstract class.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:18:25,000 --> 00:18:33,000
|
| 931 |
+
But some of the masses are abstract ones because implementation will depend on the concrete implementation
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:18:33,000 --> 00:18:36,000
|
| 935 |
+
and the specifics of normal operating system.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:18:36,000 --> 00:18:42,000
|
| 939 |
+
Pay attention that this is an absolute class so that no one can create an instance of this object.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:18:42,000 --> 00:18:45,000
|
| 943 |
+
And we have classes that extends this one.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:46,000 --> 00:18:54,000
|
| 947 |
+
We have Android compiler and ifone compiler classes, both extends across compiler and implements necessary
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:54,000 --> 00:18:57,000
|
| 951 |
+
steps that are not implemented in the parent class.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:58,000 --> 00:19:00,000
|
| 955 |
+
Now, let me show you the client code.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:19:01,000 --> 00:19:02,000
|
| 959 |
+
Here is my demo class.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:19:03,000 --> 00:19:12,000
|
| 963 |
+
I create a phone compiler first and call compile Massett and after that I create Android compiler and
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:19:12,000 --> 00:19:13,000
|
| 967 |
+
call compiler Macit.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:19:13,000 --> 00:19:15,000
|
| 971 |
+
Let me run this code.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:19:16,000 --> 00:19:24,000
|
| 975 |
+
And in console output you can see that algorithm is the same for both iPhone and Android compilers and
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:19:24,000 --> 00:19:25,000
|
| 979 |
+
some common steps.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:19:25,000 --> 00:19:33,000
|
| 983 |
+
Executer twice here you can see how subclasses give implementation to some of the steps in my algorithm.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:19:33,000 --> 00:19:35,000
|
| 987 |
+
But algorithm is the same in general.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:36,000 --> 00:19:44,000
|
| 991 |
+
One of the obvious drawback is it algorithm is hard coded and you have to rely on inheritance mechanism
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:44,000 --> 00:19:50,000
|
| 995 |
+
during the implementation of this part and you can't change algorithm or introduce new steps.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:51,000 --> 00:19:53,000
|
| 999 |
+
That's why this is not super effective.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:53,000 --> 00:20:00,000
|
| 1003 |
+
But on the other hand, helps us to avoid complication for some groups of operations that have similar
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:20:00,000 --> 00:20:01,000
|
| 1007 |
+
algorithm.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:20:01,000 --> 00:20:04,000
|
| 1011 |
+
Let's look at the checklist to implement this program.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:20:04,000 --> 00:20:09,000
|
| 1015 |
+
There are a few important items to remember when we implement template MassArt.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:20:09,000 --> 00:20:09,000
|
| 1019 |
+
Pardon?
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:20:09,000 --> 00:20:17,000
|
| 1023 |
+
They are Ximenes the algorithm and sync how to split the algorithm into different steps, create an
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:20:17,000 --> 00:20:19,000
|
| 1027 |
+
obstacle course and define template.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:20:19,000 --> 00:20:26,000
|
| 1031 |
+
Massada put each step of the algorithm in the separate method described MassArt invocation sequence
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:20:26,000 --> 00:20:27,000
|
| 1035 |
+
incomplete.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:27,000 --> 00:20:31,000
|
| 1039 |
+
Macit identified places for Hooke's in your algorithm.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:32,000 --> 00:20:36,000
|
| 1043 |
+
Create concrete classes that implements the required steps in the algorithm.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:37,000 --> 00:20:39,000
|
| 1047 |
+
That's all regarding template MassArt.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:20:39,000 --> 00:20:44,000
|
| 1051 |
+
Hope that now you know how to implement template method partner in your application.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:45,000 --> 00:20:46,000
|
| 1055 |
+
Let's proceed with the next part.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:46,000 --> 00:20:49,000
|
| 1059 |
+
On the next part is Iterator.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:49,000 --> 00:20:56,000
|
| 1063 |
+
If you have ever used Java collections framework, you may already understand what this is about and
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:56,000 --> 00:21:01,000
|
| 1067 |
+
all Java InGenius manger's implementations of Iterator Partan in JDK.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:21:02,000 --> 00:21:08,000
|
| 1071 |
+
But in case you are not a Java developer or will code on another programming language, most likely
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:21:08,000 --> 00:21:09,000
|
| 1075 |
+
you would need to implement.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:21:09,000 --> 00:21:17,000
|
| 1079 |
+
Iterate a from scratch by your own insert iterator is behavioral patterns that allows us to go over
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:21:17,000 --> 00:21:24,000
|
| 1083 |
+
each element of an aggregate object sequentially without exposing its underlying representation.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:21:25,000 --> 00:21:26,000
|
| 1087 |
+
Why is this might be needed?
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:21:26,000 --> 00:21:34,000
|
| 1091 |
+
Imagine that you have some aggregate object, and no matter whether this an array or some other container,
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:21:34,000 --> 00:21:38,000
|
| 1095 |
+
you don't want to understand the internal structure of the object.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:21:39,000 --> 00:21:45,000
|
| 1099 |
+
The only thing that you need is an interface that will allow you to get each element of this object
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:45,000 --> 00:21:50,000
|
| 1103 |
+
one by one, because the structure of containers might be different.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:51,000 --> 00:21:56,000
|
| 1107 |
+
Some of them vectors like structure and some of them are tree like structures.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:56,000 --> 00:22:00,000
|
| 1111 |
+
It is not always convenient to understand the internal structure.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:22:00,000 --> 00:22:05,000
|
| 1115 |
+
It is better to have a single common interface to iterate over each element.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:22:06,000 --> 00:22:12,000
|
| 1119 |
+
So the idea of the Iterator portal is to put all logic of iteration in the separate class iterate and
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:22:12,000 --> 00:22:17,000
|
| 1123 |
+
would also track progress of the iteration and state of iteration.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:22:17,000 --> 00:22:25,000
|
| 1127 |
+
Let's now look at the example, and this time I will not create any custom example and I will perform
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:22:25,000 --> 00:22:27,000
|
| 1131 |
+
the demo on the example of the key.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:22:27,000 --> 00:22:34,000
|
| 1135 |
+
Imagine that we have some container and it is really don't matter whether I have array based, container
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:22:34,000 --> 00:22:41,000
|
| 1139 |
+
linked based container or even hash table based container iterator interface will be the same and will
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:22:41,000 --> 00:22:45,000
|
| 1143 |
+
help you to iterate over each element in any container.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:22:45,000 --> 00:22:49,000
|
| 1147 |
+
Here in demo class, I created objects of arriviste.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:22:49,000 --> 00:22:51,000
|
| 1151 |
+
This is a container that is based on the array.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:22:52,000 --> 00:22:53,000
|
| 1155 |
+
I created the linked list.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:22:54,000 --> 00:23:01,000
|
| 1159 |
+
This is a container that is based on the linked objects and I have Hasset object Zellous container that
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:23:01,000 --> 00:23:02,000
|
| 1163 |
+
is based on hash table.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:23:02,000 --> 00:23:09,000
|
| 1167 |
+
Basically, no matter what object I will take, each object can provide me with the iterator.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:23:09,000 --> 00:23:13,000
|
| 1171 |
+
And here you can see that I get iterator for each collection.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:23:13,000 --> 00:23:16,000
|
| 1175 |
+
Let's look at the Iterator interface.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:23:16,000 --> 00:23:22,000
|
| 1179 |
+
In this particular case, Iterator provides me with MassArt has next next and remove.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:23:23,000 --> 00:23:29,000
|
| 1183 |
+
I would say that these methods are bare minimum for iterator because in addition to these ones, it
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:23:29,000 --> 00:23:36,000
|
| 1187 |
+
is also possible to implement other methods for navigation, for example, methods for navigation in
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:23:36,000 --> 00:23:40,000
|
| 1191 |
+
other direction, like previous methods for verification.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:23:40,000 --> 00:23:46,000
|
| 1195 |
+
Whether there is a previous element has previous method to get index of the current position method,
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:23:46,000 --> 00:23:53,000
|
| 1199 |
+
that new element during iteration of a container method to substitute the last return element.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:23:53,000 --> 00:23:59,000
|
| 1203 |
+
And Ingenico, we have at least iterator, but it works only for liste Iraqi anyway.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:23:59,000 --> 00:24:00,000
|
| 1207 |
+
It will be up to you.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:24:00,000 --> 00:24:07,000
|
| 1211 |
+
What methods to implement in your iterator has next method tells us whether there is a next element
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:24:07,000 --> 00:24:08,000
|
| 1215 |
+
in the sequence.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:24:08,000 --> 00:24:10,000
|
| 1219 |
+
This is super useful Macit.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:24:10,000 --> 00:24:15,000
|
| 1223 |
+
The build condition in Loop's next MassArt regions.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:24:15,000 --> 00:24:21,000
|
| 1227 |
+
The reference to the next object in the container and remove MassArt removes the last rechanged object.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:24:22,000 --> 00:24:29,000
|
| 1231 |
+
Basically, that's all interface implementation of this interface needs to consider storing the state
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:24:29,000 --> 00:24:35,000
|
| 1235 |
+
of the iteration to remember what item was returned last and what next element I should return.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:24:36,000 --> 00:24:40,000
|
| 1239 |
+
And we have a single iterator interface for all types of containers.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:24:41,000 --> 00:24:46,000
|
| 1243 |
+
In the case of Java collections framework, it is duty of each container to provide the client with
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:24:46,000 --> 00:24:48,000
|
| 1247 |
+
implementation of Étretat interface.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:24:49,000 --> 00:24:53,000
|
| 1251 |
+
Let's now switch to or at least close one eye open source.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:24:53,000 --> 00:24:59,000
|
| 1255 |
+
Sort of iterator, Masset, I see that according to Masad signature, itra transliterate a type, but
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:24:59,000 --> 00:25:07,000
|
| 1259 |
+
what implementation of this interface here you can see that new object of etre type is created and returned
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:25:08,000 --> 00:25:09,000
|
| 1263 |
+
watrous each type.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:25:10,000 --> 00:25:18,000
|
| 1267 |
+
This is in a class of a release that implements iterator interface and implements or abstract marcedes.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:25:18,000 --> 00:25:25,000
|
| 1271 |
+
As you can see, we built our code by relying on abstractions and iterator interface is one of them.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:25:25,000 --> 00:25:32,000
|
| 1275 |
+
And each container in this case is obligated to provide iterate implementation that knows the structure
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:25:32,000 --> 00:25:36,000
|
| 1279 |
+
of this container and how to iterate over each element inside this container.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:25:37,000 --> 00:25:39,000
|
| 1283 |
+
Basically, that's it.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:25:39,000 --> 00:25:43,000
|
| 1287 |
+
You can implement your own iterator if needed following this example.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:25:44,000 --> 00:25:51,000
|
| 1291 |
+
Now let's create a checklist for iterate apart and define iterate interface with at least has next and
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:25:51,000 --> 00:25:55,000
|
| 1295 |
+
next method as a method might be added to.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:25:55,000 --> 00:26:03,000
|
| 1299 |
+
As we discussed in our example, in the object that serves as a container, declare a master return
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:26:03,000 --> 00:26:10,000
|
| 1303 |
+
and iterate the great implementation of Iterator Interface for collection that you need to iterate over
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:26:11,000 --> 00:26:18,000
|
| 1307 |
+
client requests, iterate and use it for iteration of elements in container grade.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:26:18,000 --> 00:26:24,000
|
| 1311 |
+
We learned iterate a pattern and now we are going to learn the last but not the least important for
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:26:24,000 --> 00:26:24,000
|
| 1315 |
+
today.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:26:25,000 --> 00:26:29,000
|
| 1319 |
+
The next point that we are going to learn is called chain of responsibility.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:26:30,000 --> 00:26:35,000
|
| 1323 |
+
This is part that allows us to process a single request by multiple handlers.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:26:36,000 --> 00:26:44,000
|
| 1327 |
+
We build handlers in the chain and each handler is a process, request or pass the request further to
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:26:44,000 --> 00:26:45,000
|
| 1331 |
+
the next link in the chain.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:26:46,000 --> 00:26:53,000
|
| 1335 |
+
There are a few simple examples where chain of responsibility is widely used in Web applications.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:26:53,000 --> 00:26:55,000
|
| 1339 |
+
There is a concept of request filters.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:26:56,000 --> 00:27:02,000
|
| 1343 |
+
Imagine that you are sending a request to a specific page, let's say admin dashboard of your online
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:27:02,000 --> 00:27:08,000
|
| 1347 |
+
shop and there is a sequence of filters your request should go through before it reach.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:27:08,000 --> 00:27:14,000
|
| 1351 |
+
End Point and server would return you the admin dashboard page, for example.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:27:14,000 --> 00:27:17,000
|
| 1355 |
+
The first filter might be the login filter.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:27:18,000 --> 00:27:24,000
|
| 1359 |
+
This filter handles your web request and verifies whether you already logged in or now.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:27:25,000 --> 00:27:31,000
|
| 1363 |
+
If you are not logged in, your request is not passed through the chain to the next filter, but instead
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:27:32,000 --> 00:27:34,000
|
| 1367 |
+
you're redirected to the login page.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:27:35,000 --> 00:27:39,000
|
| 1371 |
+
The next filter might be authorization and authentification filter.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:27:40,000 --> 00:27:47,000
|
| 1375 |
+
This filter will verify your user in database and will check what role and privileges your user has
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:27:47,000 --> 00:27:48,000
|
| 1379 |
+
in the system.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:27:48,000 --> 00:27:54,000
|
| 1383 |
+
If your user has admin role, you will be finally redirected to the admin dashboard page.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:27:54,000 --> 00:28:00,000
|
| 1387 |
+
If not, you will be redirected to our page where you will see notification about not having enough
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:28:00,000 --> 00:28:02,000
|
| 1391 |
+
rights to access this page.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:28:03,000 --> 00:28:10,000
|
| 1395 |
+
And these filters are built into the single chain and your request pass through the each of them because
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:28:10,000 --> 00:28:13,000
|
| 1399 |
+
each filter has the reference to the next one.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:28:13,000 --> 00:28:19,000
|
| 1403 |
+
And one more important thing, hope you already understood this from my example, is that it is not
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:28:19,000 --> 00:28:22,000
|
| 1407 |
+
necessary to pass the request through the whole chain.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:28:22,000 --> 00:28:29,000
|
| 1411 |
+
It could be that some element in the chain decide to stop processing hope that high level overview of
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:28:29,000 --> 00:28:30,000
|
| 1415 |
+
this part is clear.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:28:31,000 --> 00:28:39,000
|
| 1419 |
+
Now let's jump to the example and this example will create with your software for atme will build with
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:28:39,000 --> 00:28:45,000
|
| 1423 |
+
your chain of multiple dispensers that will help and users to get the cash from the ATM.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:28:45,000 --> 00:28:46,000
|
| 1427 |
+
Let's go one by one.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:28:47,000 --> 00:28:50,000
|
| 1431 |
+
We have an interface of the span's chain.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:28:50,000 --> 00:28:51,000
|
| 1435 |
+
Let me show it.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:28:52,000 --> 00:28:59,000
|
| 1439 |
+
It has Tomas's set next link that takes object of the same type as an argument and actually dispense
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:28:59,000 --> 00:29:01,000
|
| 1443 |
+
Massett the dispense some currency.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:29:02,000 --> 00:29:03,000
|
| 1447 |
+
What is currency?
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:29:04,000 --> 00:29:10,000
|
| 1451 |
+
This is another type wrapper that contains information about cache units in one node.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:29:11,000 --> 00:29:15,000
|
| 1455 |
+
Next, we have implementations of dispense chain interface.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:29:15,000 --> 00:29:21,000
|
| 1459 |
+
We have fifty dollar dispenser, twenty dollar dispenser and dollar dispenser.
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:29:21,000 --> 00:29:23,000
|
| 1463 |
+
There are almost C.M.A.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:29:23,000 --> 00:29:29,000
|
| 1467 |
+
Besides the value of the node since they are working with and to be honest this may be written with
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:29:29,000 --> 00:29:36,000
|
| 1471 |
+
one single class, but for the sake of the demo and for visibility purposes, I decided to keep all
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:29:36,000 --> 00:29:40,000
|
| 1475 |
+
these classes to make sure you understood the chain of responsibility, partner.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:29:41,000 --> 00:29:45,000
|
| 1479 |
+
Let's now look at the dispense method of any of these classes.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:29:45,000 --> 00:29:52,000
|
| 1483 |
+
We get amount from the currency object and if it is equal or more than the value of the current dispenser.
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:29:52,000 --> 00:29:59,000
|
| 1487 |
+
Then will perform next logic when I get a number of notes that we need to give our end user and if there
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:29:59,000 --> 00:30:06,000
|
| 1491 |
+
is some remainder, I put this request further with the new currency object, with the value of remained
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:30:06,000 --> 00:30:11,000
|
| 1495 |
+
pay attention, that e.g. dispenser has reference to another dispenser in the chain.
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:30:12,000 --> 00:30:19,000
|
| 1499 |
+
This first condition verifies what is this dispenser is allowed to process this request.
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:30:19,000 --> 00:30:24,000
|
| 1503 |
+
If not in our particular case, I pass the request further to the next dispenser.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:30:25,000 --> 00:30:26,000
|
| 1507 |
+
Is that clear?
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:30:26,000 --> 00:30:29,000
|
| 1511 |
+
Let's now look at the client code in our demo class.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:30:30,000 --> 00:30:34,000
|
| 1515 |
+
In my demo class, I have field of type dispense, Jane.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:30:34,000 --> 00:30:38,000
|
| 1519 |
+
That would be my whole chain with all links in it.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:30:39,000 --> 00:30:45,000
|
| 1523 |
+
In constructor of the demo class, I create instances of all the Spenser's and connecting them in one
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:30:45,000 --> 00:30:48,000
|
| 1527 |
+
chain using set next link MassArt.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:30:49,000 --> 00:30:53,000
|
| 1531 |
+
So here we can see that fifty dollar dispenser is the first link.
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:30:53,000 --> 00:30:59,000
|
| 1535 |
+
Twenty dollars dispenser going next and then the dispenser is the last dispenser in the chain.
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:30:59,000 --> 00:31:05,000
|
| 1539 |
+
Now when I have my chain constructed let me run this program and explore it with you.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:31:06,000 --> 00:31:12,000
|
| 1543 |
+
The first thing that I do in my own method, I create the object of this type that contains dispense
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:31:12,000 --> 00:31:13,000
|
| 1547 |
+
chain.
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:31:13,000 --> 00:31:21,000
|
| 1551 |
+
After that I create infinite loop and I ask user to input the amount that he or she wants to get from
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:31:21,000 --> 00:31:21,000
|
| 1555 |
+
the ATM.
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:31:22,000 --> 00:31:28,000
|
| 1559 |
+
Let's imagine I want to dispense one hundred twenty bucks and I see that ATMs are already calculated
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:31:28,000 --> 00:31:30,000
|
| 1563 |
+
how much nodes it will give me.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:31:31,000 --> 00:31:36,000
|
| 1567 |
+
It will give me two fifty dollars nodes and one twenty dollars node.
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:31:36,000 --> 00:31:38,000
|
| 1571 |
+
Now let me request eighty bucks.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:31:39,000 --> 00:31:47,000
|
| 1575 |
+
This time a.T.M will give me one fifty dollars node, one twenty dollars node and one ten dollars node.
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:31:47,000 --> 00:31:49,000
|
| 1579 |
+
Can I understand how it works?
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:31:50,000 --> 00:31:55,000
|
| 1583 |
+
When I call dispense method here I start the request process by my change.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:31:56,000 --> 00:31:58,000
|
| 1587 |
+
One important thing that we didn't talk yet.
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:31:59,000 --> 00:32:05,000
|
| 1591 |
+
You should always bear in mind the logic of chain processing to understand what is the condition of
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:32:05,000 --> 00:32:06,000
|
| 1595 |
+
completion.
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:32:06,000 --> 00:32:10,000
|
| 1599 |
+
In our particular case, I have verification on client side here.
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:32:11,000 --> 00:32:18,000
|
| 1603 |
+
It is not allowed to request dispense amount that is not multiple of ten and I have ten dollars dispenser
|
| 1604 |
+
|
| 1605 |
+
402
|
| 1606 |
+
00:32:18,000 --> 00:32:19,000
|
| 1607 |
+
in my chain.
|
| 1608 |
+
|
| 1609 |
+
403
|
| 1610 |
+
00:32:19,000 --> 00:32:26,000
|
| 1611 |
+
That means request will go to the last link in chain for sure, because one of the risks that you might
|
| 1612 |
+
|
| 1613 |
+
404
|
| 1614 |
+
00:32:26,000 --> 00:32:32,000
|
| 1615 |
+
face with during the implementation of Chain of Responsibility pardon is that your chain will leave
|
| 1616 |
+
|
| 1617 |
+
405
|
| 1618 |
+
00:32:32,000 --> 00:32:40,000
|
| 1619 |
+
your request unprocessed just because conditions initially were not met and none of the items in your
|
| 1620 |
+
|
| 1621 |
+
406
|
| 1622 |
+
00:32:40,000 --> 00:32:41,000
|
| 1623 |
+
chain prior to the request.
|
| 1624 |
+
|
| 1625 |
+
407
|
| 1626 |
+
00:32:42,000 --> 00:32:48,000
|
| 1627 |
+
So be very careful by thinking about your condition of completion in your chain of responsibility.
|
| 1628 |
+
|
| 1629 |
+
408
|
| 1630 |
+
00:32:49,000 --> 00:32:53,000
|
| 1631 |
+
I hope that with this example it is clear how chain of responsibility works.
|
| 1632 |
+
|
| 1633 |
+
409
|
| 1634 |
+
00:32:54,000 --> 00:33:01,000
|
| 1635 |
+
Now let's review a checklist to implement chain of responsibility partan great interface of event handler
|
| 1636 |
+
|
| 1637 |
+
410
|
| 1638 |
+
00:33:01,000 --> 00:33:03,000
|
| 1639 |
+
and declare Masset of event handle.
|
| 1640 |
+
|
| 1641 |
+
411
|
| 1642 |
+
00:33:04,000 --> 00:33:10,000
|
| 1643 |
+
Make sure that each implementation of the chain interface may contain the reference to the next link
|
| 1644 |
+
|
| 1645 |
+
412
|
| 1646 |
+
00:33:10,000 --> 00:33:11,000
|
| 1647 |
+
in the chain.
|
| 1648 |
+
|
| 1649 |
+
413
|
| 1650 |
+
00:33:12,000 --> 00:33:19,000
|
| 1651 |
+
Each chain interface implementation contributes to the event handler if the request is needed to be
|
| 1652 |
+
|
| 1653 |
+
414
|
| 1654 |
+
00:33:19,000 --> 00:33:19,000
|
| 1655 |
+
passed.
|
| 1656 |
+
|
| 1657 |
+
415
|
| 1658 |
+
00:33:19,000 --> 00:33:24,000
|
| 1659 |
+
Forward Link Object calls the MassArt on the next element in the chain.
|
| 1660 |
+
|
| 1661 |
+
416
|
| 1662 |
+
00:33:25,000 --> 00:33:32,000
|
| 1663 |
+
Client creates change depending on the business logic and launches chain from the route that sets regarding
|
| 1664 |
+
|
| 1665 |
+
417
|
| 1666 |
+
00:33:32,000 --> 00:33:33,000
|
| 1667 |
+
chain of responsibility.
|
| 1668 |
+
|
| 1669 |
+
418
|
| 1670 |
+
00:33:34,000 --> 00:33:37,000
|
| 1671 |
+
Now let's recap what we have learned in this lesson.
|
| 1672 |
+
|
| 1673 |
+
419
|
| 1674 |
+
00:33:38,000 --> 00:33:45,000
|
| 1675 |
+
In this lesson, we learned five, in my opinion, the most popular behavioral patterns that strategy
|
| 1676 |
+
|
| 1677 |
+
420
|
| 1678 |
+
00:33:45,000 --> 00:33:50,000
|
| 1679 |
+
command template, MassArt, iterator and chain of responsibility.
|
| 1680 |
+
|
| 1681 |
+
421
|
| 1682 |
+
00:33:51,000 --> 00:33:52,000
|
| 1683 |
+
Thanks a lot for your attention.
|
| 1684 |
+
|
| 1685 |
+
422
|
| 1686 |
+
00:33:52,000 --> 00:33:55,000
|
| 1687 |
+
Have a great day and see you in the next lesson.
|
| 1688 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/005 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
39 - GoF Design Patterns of Software Architecture in OOP/006 Behevioral Patterns, p.2_en.srt
ADDED
|
@@ -0,0 +1,1636 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello, team, we proceed learning of behavioral patterns, we already started learning some of them
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:18,000
|
| 7 |
+
in previous lesson and we'll continue in this one in this class and going with your next pardon's visitor,
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:18,000 --> 00:00:23,000
|
| 11 |
+
state observer momentum and as always, for each part.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:23,000 --> 00:00:27,000
|
| 15 |
+
And you can find source code examples in attachments to this video.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:27,000 --> 00:00:30,000
|
| 19 |
+
We'll explore those examples today during the lesson.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:31,000 --> 00:00:36,000
|
| 23 |
+
But it is always a good idea to upload those good examples in your local computer and to run them to
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:36,000 --> 00:00:39,000
|
| 27 |
+
understand better how everything is working.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:39,000 --> 00:00:40,000
|
| 31 |
+
Let's start.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:41,000 --> 00:00:45,000
|
| 35 |
+
And the first part is that we are going to learn today is visit partner insured.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:45,000 --> 00:00:52,000
|
| 39 |
+
This panel lets us define a new operation without changing the classes of the elements on which it operates.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:53,000 --> 00:00:59,000
|
| 43 |
+
Probably the first question that pops up in the minds of my students is how a different Xenephon decorate
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:59,000 --> 00:01:04,000
|
| 47 |
+
the podium because the goal of the curator is similar, but only at the first glance.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:05,000 --> 00:01:11,000
|
| 51 |
+
Let's have an overview of the pardon and after that will perform comparative analysis between visitor
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:11,000 --> 00:01:12,000
|
| 55 |
+
and decorator.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:12,000 --> 00:01:17,000
|
| 59 |
+
Imagine that you're implementing online map and you have geia objects.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:18,000 --> 00:01:23,000
|
| 63 |
+
Each object consists from your data and information about the specific object on the map.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:24,000 --> 00:01:27,000
|
| 67 |
+
It also contains information about the nearest objects.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:27,000 --> 00:01:33,000
|
| 71 |
+
This allows us to build a graph of objects that are connected with each other, and that's how we can
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:33,000 --> 00:01:41,000
|
| 75 |
+
create map and imagine that new business requirement makes you do an excellent expert of Hoess graph
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:41,000 --> 00:01:45,000
|
| 79 |
+
of objects to process this data for separate purposes.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:45,000 --> 00:01:52,000
|
| 83 |
+
And this task will be easy in case you would be able to adjust the Gernhardt Iraqi and implement MassArt
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:52,000 --> 00:01:54,000
|
| 87 |
+
in each class of Gernhardt Iraqi.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:54,000 --> 00:01:57,000
|
| 91 |
+
That describes the way how something should be exported.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:58,000 --> 00:02:05,000
|
| 95 |
+
But Geotech Lead asked you do not dodgiest these classes and types since this is considered to be a
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:05,000 --> 00:02:10,000
|
| 99 |
+
stable code already and a lot of other modules depend on this code.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:10,000 --> 00:02:18,000
|
| 103 |
+
Also attacked it passed this course already and he knows basic principles and principles of Glynco design.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:18,000 --> 00:02:24,000
|
| 107 |
+
Dependancy should go in the direction of stable modules and we shouldn't change those.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:24,000 --> 00:02:26,000
|
| 111 |
+
And above that expert behavior.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:27,000 --> 00:02:32,000
|
| 115 |
+
This is not necessarily what should be logically present in object type agree.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:32,000 --> 00:02:38,000
|
| 119 |
+
Sounds like this is not natural behavior for such types of objects and we will violate single responsibility,
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:38,000 --> 00:02:43,000
|
| 123 |
+
principle and the last reason to not adjust all existing classes.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:43,000 --> 00:02:50,000
|
| 127 |
+
Imagine that next week to do expert in another format, not ximo but JSON as example.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:50,000 --> 00:02:53,000
|
| 131 |
+
What to do in this case, change all classes again.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:54,000 --> 00:02:54,000
|
| 135 |
+
No way.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:55,000 --> 00:03:01,000
|
| 139 |
+
And still, what do you have to do in this case and where you will add behavior of experts in this data
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:01,000 --> 00:03:09,000
|
| 143 |
+
into ximo visitor or for us to store over here in the separate class instead of adding this behavior
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:09,000 --> 00:03:12,000
|
| 147 |
+
to all classes objects that should do something.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:12,000 --> 00:03:19,000
|
| 151 |
+
In this case, the behavior of expert data to ximo need to be passed to the new class instead of Collinses
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:19,000 --> 00:03:21,000
|
| 155 |
+
behavior on the existing objects.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:21,000 --> 00:03:28,000
|
| 159 |
+
It seems that we want to be able to create generic masset that will work for all different types because
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:28,000 --> 00:03:33,000
|
| 163 |
+
each tag would have different structure and we should consider this when interacting with it.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:33,000 --> 00:03:40,000
|
| 167 |
+
Definitely all these matters will do the same, but type of input argument will be different and the
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:40,000 --> 00:03:44,000
|
| 171 |
+
way how we interact with objects and sides and Masset might be different.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:44,000 --> 00:03:47,000
|
| 175 |
+
I hope you understood this example, at least on the high level.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:47,000 --> 00:03:49,000
|
| 179 |
+
Now let's have a number of visits.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:49,000 --> 00:03:54,000
|
| 183 |
+
A pardon will implement exactly the same example that I've just talked about.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:55,000 --> 00:03:58,000
|
| 187 |
+
Let's start from abstractions that we have Geor aliment.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:59,000 --> 00:04:02,000
|
| 191 |
+
This is abstraction over all other elements.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:02,000 --> 00:04:07,000
|
| 195 |
+
On my online map, we have multiple types that implements this interface.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:07,000 --> 00:04:13,000
|
| 199 |
+
They are industrial building park, private building and shopping centre.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:13,000 --> 00:04:17,000
|
| 203 |
+
In this particular example, I have only one abstract method in here.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:18,000 --> 00:04:21,000
|
| 207 |
+
Accept this method, accepts Visita.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:22,000 --> 00:04:27,000
|
| 211 |
+
That is exactly the message that we need to implement in all our major elements in order for us to be
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:27,000 --> 00:04:30,000
|
| 215 |
+
able to scale our architecture.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:30,000 --> 00:04:34,000
|
| 219 |
+
As far as you understand, visiter is another abstraction.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:34,000 --> 00:04:35,000
|
| 223 |
+
Let's look at it.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:36,000 --> 00:04:41,000
|
| 227 |
+
This is abstract type that declares mass amount of work with each particular type.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:42,000 --> 00:04:49,000
|
| 231 |
+
Even despite industrial building, part private building and shopping center have common interface that
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:49,000 --> 00:04:55,000
|
| 235 |
+
is larger and they still might have type specific masses that we need to consider while working with
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:55,000 --> 00:04:55,000
|
| 239 |
+
them.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:56,000 --> 00:04:59,000
|
| 243 |
+
That's why we have separate method for each specific type.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:59,000 --> 00:05:03,000
|
| 247 |
+
Naming convention for this message and practice might be different.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:03,000 --> 00:05:10,000
|
| 251 |
+
For example, you can call them like this or just call them visit, and you have different variations
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:10,000 --> 00:05:14,000
|
| 255 |
+
and implementations of this visitor in this particular example.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:14,000 --> 00:05:17,000
|
| 259 |
+
I have one more interface that extends this one.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:17,000 --> 00:05:24,000
|
| 263 |
+
It is called Experts Visit, that potentially this interface might be an abstract class, but the difference
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:24,000 --> 00:05:30,000
|
| 267 |
+
about abstract classes and interface and when to use what which might complete Java course in lessons
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:30,000 --> 00:05:33,000
|
| 271 |
+
about interface and abstract classes.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:33,000 --> 00:05:40,000
|
| 275 |
+
You can see that in this public default method, we take variable list of arguments of the element type.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:41,000 --> 00:05:49,000
|
| 279 |
+
And when iterating over them, we call accept Masset on it and pass this visit to the visitor that invoked
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:49,000 --> 00:05:51,000
|
| 283 |
+
this expert MASP.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:51,000 --> 00:05:52,000
|
| 287 |
+
Is that clear?
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:53,000 --> 00:05:57,000
|
| 291 |
+
The next thing that I need to share with you is how accepting method is implemented.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:58,000 --> 00:06:05,000
|
| 295 |
+
For example, let me open industrial building class and accept that you can see that I invoke Masset
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:05,000 --> 00:06:12,000
|
| 299 |
+
specific to this type on visitor object that was passed and argument and patterns of reference to this
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:12,000 --> 00:06:13,000
|
| 303 |
+
object as a method argument.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:14,000 --> 00:06:19,000
|
| 307 |
+
So now let's jump to implementation of dofor industrial building method.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:19,000 --> 00:06:25,000
|
| 311 |
+
This method is implemented in XML expert visitor Andrew Sun, expert visitor.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:25,000 --> 00:06:27,000
|
| 315 |
+
Most of them implements experts visita.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:28,000 --> 00:06:34,000
|
| 319 |
+
And you can see that in this particular case I just print text to console to indicate that this specific
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:34,000 --> 00:06:38,000
|
| 323 |
+
method was invoked either from Ximo or Drayson expert visiter class.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:39,000 --> 00:06:42,000
|
| 327 |
+
And now let's open, for example, a shopping center class.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:43,000 --> 00:06:48,000
|
| 331 |
+
You can see that this class might have a little bit different set of properties and different getters
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:48,000 --> 00:06:54,000
|
| 335 |
+
and setters, but the only thing that we are interested in is implementation of except Macit.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:55,000 --> 00:06:58,000
|
| 339 |
+
And we can see that this is similar to what we saw in another class.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:59,000 --> 00:07:05,000
|
| 343 |
+
Yes, we adjusted these classes with implementation of one single method, but implementation of this
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:05,000 --> 00:07:11,000
|
| 347 |
+
method will allow us to implement any visitor we want and pass it to this class.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:11,000 --> 00:07:17,000
|
| 351 |
+
That additional behavior you want to add new behavior to all types, just create new visitor type and
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:17,000 --> 00:07:17,000
|
| 355 |
+
that's it.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:18,000 --> 00:07:19,000
|
| 359 |
+
Does it make sense?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:19,000 --> 00:07:21,000
|
| 363 |
+
Pretty cool, don't you think so?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:21,000 --> 00:07:25,000
|
| 367 |
+
And now let's look at the demo class to explore client code.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:25,000 --> 00:07:29,000
|
| 371 |
+
Let me run this file and explore console output together with you.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:29,000 --> 00:07:37,000
|
| 375 |
+
Imagine that I created objects of different types, park buildings, etc. After that, I create a reference
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:37,000 --> 00:07:44,000
|
| 379 |
+
of expert visitor type and pointed to X amount expert visitor object after I call expert Masset and
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:44,000 --> 00:07:49,000
|
| 383 |
+
person alja aliments as Masad arguments and what we have.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:49,000 --> 00:07:56,000
|
| 387 |
+
And so we have indication of Masset invocations from external expert visitor object for each element.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:57,000 --> 00:08:03,000
|
| 391 |
+
After that I have separation Mark and now I point my reference to the adjacent expert visitor object
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:03,000 --> 00:08:05,000
|
| 395 |
+
and cause the same method.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:05,000 --> 00:08:13,000
|
| 399 |
+
What I see and console absolutely new behavior added to already created objects is a basic yes, we
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:13,000 --> 00:08:19,000
|
| 403 |
+
did a lot of preparations, but just take a look how elegant the solution is, not only elegant but
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:19,000 --> 00:08:22,000
|
| 407 |
+
house capabilities to implement additional behavior.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:22,000 --> 00:08:25,000
|
| 411 |
+
You don't need to touch asset classes anymore.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:25,000 --> 00:08:28,000
|
| 415 |
+
Just implement new visiter and that's it.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:29,000 --> 00:08:31,000
|
| 419 |
+
Hope you understood visitor partner with this example.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:32,000 --> 00:08:38,000
|
| 423 |
+
Now let's create a checklist for implementation of the plan to implement visitor button, follow next
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:38,000 --> 00:08:45,000
|
| 427 |
+
steps, create visitor interface and declare assets to visit each class of the elements Iraqi unit to
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:45,000 --> 00:08:49,000
|
| 431 |
+
work with, declare and describe interface of elements.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:50,000 --> 00:08:57,000
|
| 435 |
+
In our particular example, it was element implement element interface in each concrete implementation
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:58,000 --> 00:09:03,000
|
| 439 |
+
hierarchy of elements need to be aware only about the most abstract type of visitors.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:04,000 --> 00:09:11,000
|
| 443 |
+
On the other hand, Irakere of visitors should know all concrete implementations of element Iraqi for
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:11,000 --> 00:09:17,000
|
| 447 |
+
each new behavior, create concrete implementation of visitor interface, client will create visitor
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:17,000 --> 00:09:22,000
|
| 451 |
+
objects, and then will pass it to the acceptance method of each concrete element.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:23,000 --> 00:09:23,000
|
| 455 |
+
That's it.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:23,000 --> 00:09:24,000
|
| 459 |
+
Regarding Visitor Pardon.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:25,000 --> 00:09:29,000
|
| 463 |
+
And before we move further, let's compare visitor and decorate pardons.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:30,000 --> 00:09:34,000
|
| 467 |
+
Hopefully now after this example, you already understood the difference.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:34,000 --> 00:09:38,000
|
| 471 |
+
The main difference is that visitor works with a group of objects.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:39,000 --> 00:09:45,000
|
| 475 |
+
This pardon suggests a way how we can add new behavior to the group of objects.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:45,000 --> 00:09:51,000
|
| 479 |
+
The greater part and on the other hand works on adding decoration with additional behavior, a single
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:51,000 --> 00:09:52,000
|
| 483 |
+
instance.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:52,000 --> 00:09:58,000
|
| 487 |
+
So we can say that decorator works on an object, but the visitor works on Iraqi of elements.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:59,000 --> 00:10:03,000
|
| 491 |
+
This is probably the one biggest reason why these patterns are different.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:04,000 --> 00:10:09,000
|
| 495 |
+
Now, let's proceed with the next part, let's learn what State Department is all about.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:09,000 --> 00:10:16,000
|
| 499 |
+
The main idea of such behavior upon a state has been able to alter object behavior when its internal
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:16,000 --> 00:10:17,000
|
| 503 |
+
state changes.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:18,000 --> 00:10:23,000
|
| 507 |
+
An object might be in one of predefined states that constantly change each other.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:24,000 --> 00:10:29,000
|
| 511 |
+
Group of such states is predefined and limited and dependent on the state of the object.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:29,000 --> 00:10:34,000
|
| 515 |
+
As a specific moment of time, object may react differently on the same events.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:35,000 --> 00:10:41,000
|
| 519 |
+
For example, imagine that you are implementing online document flow system and each document may have
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:41,000 --> 00:10:48,000
|
| 523 |
+
such states draft in moderation published in each of these states publish.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:48,000 --> 00:10:54,000
|
| 527 |
+
Masset will lead us to different behavior of document object because when I invoke published method
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:54,000 --> 00:10:58,000
|
| 531 |
+
for object that is in draft state, I need to send it to my generation first.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:59,000 --> 00:11:01,000
|
| 535 |
+
When document is in moderation.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:01,000 --> 00:11:08,000
|
| 539 |
+
State and I could publish a massive document as published, but only with one condition that this was
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:08,000 --> 00:11:14,000
|
| 543 |
+
done by the administrator in case the document already in published state and I could publish, nothing
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:14,000 --> 00:11:15,000
|
| 547 |
+
should happen.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:15,000 --> 00:11:19,000
|
| 551 |
+
But the interesting thing is how would you implement this point?
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:19,000 --> 00:11:25,000
|
| 555 |
+
Because the first idea that probably pops up in your mind is to implement MassArt with multiple if statements
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:26,000 --> 00:11:27,000
|
| 559 |
+
or just have speech block.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:27,000 --> 00:11:29,000
|
| 563 |
+
And that is enough with the thing.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:30,000 --> 00:11:31,000
|
| 567 |
+
But I would say one thing.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:32,000 --> 00:11:36,000
|
| 571 |
+
You're watching this course to learn better ways to solve this than just put Swedenborg.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:37,000 --> 00:11:42,000
|
| 575 |
+
Imagine how you would acetates if it would be needed and your behavior for that state, how it will
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:42,000 --> 00:11:45,000
|
| 579 |
+
look like with Swedenborg always multiple if statements.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:46,000 --> 00:11:50,000
|
| 583 |
+
So the solution would be to create a separate class for each state and put chords.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:50,000 --> 00:11:57,000
|
| 587 |
+
That is related exactly for that behavior in those classes, instead of one single object, you're going
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:57,000 --> 00:12:03,000
|
| 591 |
+
to have so called context object that holds the reference to the state object and will delegate certain
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:03,000 --> 00:12:10,000
|
| 595 |
+
locations to that object will use polymorphism principle of object oriented programming in this part
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:10,000 --> 00:12:17,000
|
| 599 |
+
and by using common interface for all possible states and delegating calls to different objects without
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:17,000 --> 00:12:18,000
|
| 603 |
+
relying on each specific type.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:19,000 --> 00:12:21,000
|
| 607 |
+
Is it clear on the high level?
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:21,000 --> 00:12:27,000
|
| 611 |
+
If yes, then we are ready to dive into the details and explore source code example of state power.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:28,000 --> 00:12:30,000
|
| 615 |
+
And let's start this demo from the client code.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:31,000 --> 00:12:36,000
|
| 619 |
+
Let me run those Democrats to walk you through the console output and the whole classes that we have.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:36,000 --> 00:12:43,000
|
| 623 |
+
In this example, I have implemented the example with online system of document flow, very simple version
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:43,000 --> 00:12:46,000
|
| 627 |
+
of it, but still real life scenarios.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:47,000 --> 00:12:50,000
|
| 631 |
+
Imagine that client of your code creates document object.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:51,000 --> 00:12:54,000
|
| 635 |
+
And we also have different types of users in our context.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:55,000 --> 00:12:59,000
|
| 639 |
+
One user has admin role and another user has content creators role.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:00,000 --> 00:13:01,000
|
| 643 |
+
Let me open a user class.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:02,000 --> 00:13:08,000
|
| 647 |
+
So as you can see, this is super simple class with two fields only, just real name and nickname.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:09,000 --> 00:13:12,000
|
| 651 |
+
We have constructor it allows us is an initialized state of this object.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:13,000 --> 00:13:15,000
|
| 655 |
+
Let's get back to the demo file.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:15,000 --> 00:13:19,000
|
| 659 |
+
And when I just created my document, what state does it have?
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:19,000 --> 00:13:22,000
|
| 663 |
+
I believe we can call such state as a draft.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:22,000 --> 00:13:28,000
|
| 667 |
+
You can see that I called print status Masset on the document object to print state of the document
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:28,000 --> 00:13:28,000
|
| 671 |
+
to consult.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:29,000 --> 00:13:36,000
|
| 675 |
+
And you can see that there is no information about who created this document nor moderated it or published.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:36,000 --> 00:13:39,000
|
| 679 |
+
And we can see that the document is in draft state right now.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:40,000 --> 00:13:47,000
|
| 683 |
+
And I imagine that somewhere on Web user interface musterers the API call, you want to perform publishing
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:47,000 --> 00:13:47,000
|
| 687 |
+
of the document.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:48,000 --> 00:13:54,000
|
| 691 |
+
And when I perform publish behavior with the credentials of content creator user for my document, how
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:54,000 --> 00:14:00,000
|
| 695 |
+
I would expect it to behave, I would like to capture the nickname of a user that created this document
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:00,000 --> 00:14:04,000
|
| 699 |
+
and send it to my generation before publishing to the production environment.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:04,000 --> 00:14:08,000
|
| 703 |
+
Also, state of the document should be changed to the next one.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:08,000 --> 00:14:09,000
|
| 707 |
+
In my flow.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:09,000 --> 00:14:12,000
|
| 711 |
+
The next state is in moderation, correct?
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:13,000 --> 00:14:19,000
|
| 715 |
+
Right after I could publish Masset, I could print status message to print to consult current status
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:19,000 --> 00:14:20,000
|
| 719 |
+
of document object.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:20,000 --> 00:14:27,000
|
| 723 |
+
Now we can see that state is different because after I called published Masset, I initialised created
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:27,000 --> 00:14:33,000
|
| 727 |
+
by Field and took the nickname of users at different publish operation and also state.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:33,000 --> 00:14:36,000
|
| 731 |
+
Of our document right now is in moderation.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:36,000 --> 00:14:40,000
|
| 735 |
+
The next step is to complete moderation and publish this document.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:41,000 --> 00:14:47,000
|
| 739 |
+
I call Publish Macit One More Time with content creator user and I see the certification.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:47,000 --> 00:14:54,000
|
| 743 |
+
You are not admin and can't publish content and in the document status we see that no change has happened.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:55,000 --> 00:15:02,000
|
| 747 |
+
So does that mean that I call the same method to publish and the behavior is different because previously
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:02,000 --> 00:15:03,000
|
| 751 |
+
we just kept.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:03,000 --> 00:15:05,000
|
| 755 |
+
The nickname of creator, and that's it.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:06,000 --> 00:15:12,000
|
| 759 |
+
Let's now call the same method, but will pass user with admin role to this massive what will happen
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:12,000 --> 00:15:13,000
|
| 763 |
+
now.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:13,000 --> 00:15:20,000
|
| 767 |
+
I see another notification and console document is published now and status of the document object is
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:20,000 --> 00:15:21,000
|
| 771 |
+
also changed.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:21,000 --> 00:15:26,000
|
| 775 |
+
Now we have a nickname of user who performed veneration of the document and who published it.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:26,000 --> 00:15:33,000
|
| 779 |
+
As you can understand, the same method publishing behaves differently depending on the current state
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:33,000 --> 00:15:33,000
|
| 783 |
+
of the object.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:34,000 --> 00:15:39,000
|
| 787 |
+
What will happen in case I would call publish MassArt once the document is published already I see it
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:39,000 --> 00:15:40,000
|
| 791 |
+
as a notification.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:40,000 --> 00:15:43,000
|
| 795 |
+
Tell me that document is published already.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:43,000 --> 00:15:45,000
|
| 799 |
+
Pretty cool, don't you think so?
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:45,000 --> 00:15:52,000
|
| 803 |
+
And now the most interesting seeing how all this is implemented, I would like to start from document
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:52,000 --> 00:15:55,000
|
| 807 |
+
class among all different fields that describe it.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:55,000 --> 00:15:58,000
|
| 811 |
+
State a field of type state.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:58,000 --> 00:16:00,000
|
| 815 |
+
Let's check what it is.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:01,000 --> 00:16:06,000
|
| 819 |
+
As we can see, state is just a public interface that declares contract only for one method.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:07,000 --> 00:16:11,000
|
| 823 |
+
That is our publish masset that takes user as method argument.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:11,000 --> 00:16:18,000
|
| 827 |
+
We have a document state asset class that implements this interface and we have three concrete classes
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:18,000 --> 00:16:23,000
|
| 831 |
+
that extends the current state class Tsar's implements state interface.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:16:23,000 --> 00:16:28,000
|
| 835 |
+
In this specific case, I decided to have this abstract class just to not duplicate this constructor
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:28,000 --> 00:16:33,000
|
| 839 |
+
and field because an implementation of document states should have this field.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:16:33,000 --> 00:16:40,000
|
| 843 |
+
And here my three states draft state in the nation state and published state for each state.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:16:40,000 --> 00:16:43,000
|
| 847 |
+
I have separate object and published method in each state.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:43,000 --> 00:16:49,000
|
| 851 |
+
Class is implemented as it is needed for this specific state in draft state published method change
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:49,000 --> 00:16:56,000
|
| 855 |
+
state of the document to in moderation state and set create a nickname Immoderation State published
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:56,000 --> 00:17:00,000
|
| 859 |
+
method to verify the role of the users to request this behavior.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:00,000 --> 00:17:07,000
|
| 863 |
+
And if role is applicable, then we change state to published and populate data into moderated by and
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:17:07,000 --> 00:17:09,000
|
| 867 |
+
published by fields of document object.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:17:10,000 --> 00:17:17,000
|
| 871 |
+
If user doesn't have admin role, then we do nothing and just print notification to consult in published
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:17,000 --> 00:17:17,000
|
| 875 |
+
state.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:17,000 --> 00:17:21,000
|
| 879 |
+
I do nothing at all and just bring notification to council.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:21,000 --> 00:17:22,000
|
| 883 |
+
Is that clear?
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:17:23,000 --> 00:17:29,000
|
| 887 |
+
I believe at this some is saying that I still didn't share with you is how masses of state objects and
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:17:29,000 --> 00:17:35,000
|
| 891 |
+
vote if I interact not with state objects but was document object directly.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:17:35,000 --> 00:17:39,000
|
| 895 |
+
As you remember, we have state objects inside my document class.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:17:39,000 --> 00:17:45,000
|
| 899 |
+
So the only thing that is left to do is to delegate cause to the state objects when time comes.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:46,000 --> 00:17:52,000
|
| 903 |
+
For such purposes, I implemented the method with the signature that I need and just delegate this behavior
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:52,000 --> 00:17:53,000
|
| 907 |
+
to my state object.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:54,000 --> 00:17:57,000
|
| 911 |
+
My document object also has set up for state.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:57,000 --> 00:18:04,000
|
| 915 |
+
That's why I can easily perform under operations by setting previs state to my document object.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:18:04,000 --> 00:18:06,000
|
| 919 |
+
Basically, that's it.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:18:06,000 --> 00:18:10,000
|
| 923 |
+
And that is how State Department is implemented in this example.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:18:10,000 --> 00:18:15,000
|
| 927 |
+
You're welcome to find the source code in attachments to this lesson and run it on your computer.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:18:16,000 --> 00:18:21,000
|
| 931 |
+
And in case you have any questions regarding this pardon, let me know in Q&A section of this course.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:18:22,000 --> 00:18:28,000
|
| 935 |
+
Now let's create a checklist to help you implement state pardon in your project to implement state pardon.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:18:28,000 --> 00:18:29,000
|
| 939 |
+
Follow next steps.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:18:30,000 --> 00:18:37,000
|
| 943 |
+
The final Iraqi of state of your domain object, great implementations and complete classes of states
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:37,000 --> 00:18:42,000
|
| 947 |
+
implementing behaviors that should be different based on state of your domain object.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:42,000 --> 00:18:44,000
|
| 951 |
+
Make sure you have API to pass.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:44,000 --> 00:18:49,000
|
| 955 |
+
Object to state classes is a very constructor set of business logic methods.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:50,000 --> 00:18:57,000
|
| 959 |
+
Make sure that your domain object contains a reference to the most relevant state object at the state
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:57,000 --> 00:18:57,000
|
| 963 |
+
of the main object.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:57,000 --> 00:19:02,000
|
| 967 |
+
When needed delegate method calls on the main object to current state object.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:19:03,000 --> 00:19:09,000
|
| 971 |
+
In this case, you will have different behavior of your object dependent on its state that it holds
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:19:09,000 --> 00:19:14,000
|
| 975 |
+
that now you have all knowledge to implement state in the application when it will be needed.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:19:15,000 --> 00:19:16,000
|
| 979 |
+
Let's continue now.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:19:16,000 --> 00:19:18,000
|
| 983 |
+
Let's learn the next part.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:19:18,000 --> 00:19:22,000
|
| 987 |
+
The next part in our lesson today is observe upon in simple words.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:23,000 --> 00:19:29,000
|
| 991 |
+
Observe is a behavioral patterns that creates mechanisms that allow us to track events in other objects
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:29,000 --> 00:19:32,000
|
| 995 |
+
and react on these events when it might be needed.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:32,000 --> 00:19:34,000
|
| 999 |
+
Imagine the next case.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:34,000 --> 00:19:41,000
|
| 1003 |
+
You have an online store and a group of customers that are interested in the product that is currently
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:41,000 --> 00:19:45,000
|
| 1007 |
+
absent in your store, but you expect a new consignment to arrive soon.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:45,000 --> 00:19:48,000
|
| 1011 |
+
What would be the best way to solve this issue?
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:49,000 --> 00:19:52,000
|
| 1015 |
+
And he would recommend our customers change the products each day.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:53,000 --> 00:19:57,000
|
| 1019 |
+
They might be disappointed to learn that you don't have this product five days in a row.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:58,000 --> 00:20:02,000
|
| 1023 |
+
Sending messages to all customers is not a good scene because a lot of.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:20:03,000 --> 00:20:05,000
|
| 1027 |
+
Might be not interested in this product.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:20:05,000 --> 00:20:10,000
|
| 1031 |
+
I would become angry about you spun and then it would be perfect.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:20:10,000 --> 00:20:11,000
|
| 1035 |
+
That's when you will receive goods.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:11,000 --> 00:20:16,000
|
| 1039 |
+
You would instantly notify only those customers who was interested in this product.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:17,000 --> 00:20:17,000
|
| 1043 |
+
Agreed.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:18,000 --> 00:20:20,000
|
| 1047 |
+
That is why we need to observe a pattern.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:20:20,000 --> 00:20:27,000
|
| 1051 |
+
Observable trends, changes in your store, and once updates will be observable, notify your customers
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:27,000 --> 00:20:31,000
|
| 1055 |
+
to make them come to your shop and purchase the products they expected.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:32,000 --> 00:20:33,000
|
| 1059 |
+
How this is implemented.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:34,000 --> 00:20:39,000
|
| 1063 |
+
Observer registers objects that want to track changes and wants even this happened.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:39,000 --> 00:20:47,000
|
| 1067 |
+
Broadcast this news to all list of references that it stores inside and the type of objects that registered
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:47,000 --> 00:20:52,000
|
| 1071 |
+
doesn't matter because all of them have to follow quencher described in common interface.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:53,000 --> 00:20:57,000
|
| 1075 |
+
This contract of updating about the event does make sense.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:58,000 --> 00:21:00,000
|
| 1079 |
+
Hope that you understood the idea of this forum.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:21:00,000 --> 00:21:07,000
|
| 1083 |
+
Now, let's jump to example of this parren will implement scenarios that I've just described with online
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:21:07,000 --> 00:21:10,000
|
| 1087 |
+
store and customers who are pending order.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:21:10,000 --> 00:21:15,000
|
| 1091 |
+
We should notify customers who abandon their products arrived to the store.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:21:15,000 --> 00:21:18,000
|
| 1095 |
+
Let me open them a file and explain this.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:21:18,000 --> 00:21:20,000
|
| 1099 |
+
This example line by line.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:20,000 --> 00:21:23,000
|
| 1103 |
+
I create object of online store type first.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:23,000 --> 00:21:29,000
|
| 1107 |
+
After that I create a different type of customers and adds a reference to my store object.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:29,000 --> 00:21:35,000
|
| 1111 |
+
Into that, we have two types of customers, direct consumers and some other shops.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:21:36,000 --> 00:21:40,000
|
| 1115 |
+
Thus our B2B customers equate to B2C customers.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:21:40,000 --> 00:21:47,000
|
| 1119 |
+
That is business to customer model and one B2B customer that is business to business model there.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:21:47,000 --> 00:21:48,000
|
| 1123 |
+
Almost similar.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:21:48,000 --> 00:21:52,000
|
| 1127 |
+
For the sake of the example today, let me open B2C customer class.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:21:53,000 --> 00:22:00,000
|
| 1131 |
+
We can see that in this particular case I use online store reference to subscribe customer to the changes
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:22:00,000 --> 00:22:07,000
|
| 1135 |
+
I call this method and listener because we add objects that once the recent events in online store.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:22:07,000 --> 00:22:09,000
|
| 1139 |
+
Let's explore how this method works.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:22:10,000 --> 00:22:16,000
|
| 1143 |
+
Inside online store object, we have a list of observers, our group, all of them in one container
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:22:16,000 --> 00:22:20,000
|
| 1147 |
+
in order to interact with them later, as was a group of elements.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:22:20,000 --> 00:22:25,000
|
| 1151 |
+
Let's now get back to them a file after that Acrassicauda object.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:22:25,000 --> 00:22:31,000
|
| 1155 |
+
For the sake of our demo, we'll use the scanner to imitate some event from outside.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:22:31,000 --> 00:22:36,000
|
| 1159 |
+
Let me run this program now and I can see question in console.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:22:36,000 --> 00:22:43,000
|
| 1163 |
+
I just arrived to the store and in our source code you can see that I declared variable of type boolean
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:22:43,000 --> 00:22:44,000
|
| 1167 |
+
and started a loop.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:22:44,000 --> 00:22:50,000
|
| 1171 |
+
Until this variable will be true, I will be iterating and this loop and we will keep asking the same
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:22:50,000 --> 00:22:51,000
|
| 1175 |
+
question.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:22:52,000 --> 00:22:57,000
|
| 1179 |
+
For example, let's answer now to our program that we still expect on arrival.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:22:57,000 --> 00:23:03,000
|
| 1183 |
+
I'm right here and press enter and here we are again in the same loop.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:23:04,000 --> 00:23:06,000
|
| 1187 |
+
Let me now enter through and press enter.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:23:07,000 --> 00:23:12,000
|
| 1191 |
+
After this we go out of this loop and we have set a new state to our online store.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:23:12,000 --> 00:23:17,000
|
| 1195 |
+
That is exactly update that all subscribers want to know about.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:23:17,000 --> 00:23:20,000
|
| 1199 |
+
Let's explore the source code of sad state statements.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:23:21,000 --> 00:23:24,000
|
| 1203 |
+
First of all, update state of online store.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:23:24,000 --> 00:23:27,000
|
| 1207 |
+
And again, this is just an example.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:23:27,000 --> 00:23:33,000
|
| 1211 |
+
And in real life, we would have a little bit more complex even system in this particular example.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:23:33,000 --> 00:23:35,000
|
| 1215 |
+
This is just one field.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:23:35,000 --> 00:23:42,000
|
| 1219 |
+
And once we updated state of our online store, we could notify subscribers nested inside the mass that
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:23:42,000 --> 00:23:47,000
|
| 1223 |
+
we have for each loop, iterating over each observer that we have registered in this class.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:23:48,000 --> 00:23:52,000
|
| 1227 |
+
And for an interface that we agreed on, I call update method.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:23:52,000 --> 00:23:59,000
|
| 1231 |
+
After the date method, each customer prints the text to console and you can implement any business
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:23:59,000 --> 00:24:01,000
|
| 1235 |
+
logic you need to handle this.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:24:01,000 --> 00:24:06,000
|
| 1239 |
+
And now we receive an event in all subscribers that we registered in our online store.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:24:07,000 --> 00:24:08,000
|
| 1243 |
+
Does it make more sense now?
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:24:09,000 --> 00:24:09,000
|
| 1247 |
+
Great.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:24:10,000 --> 00:24:16,000
|
| 1251 |
+
Let's now create the checklist for observer part to implement observer upon follow next steps.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:24:16,000 --> 00:24:23,000
|
| 1255 |
+
Separate, dependent and independent behavior dependent behavior should be executed in case when some
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:24:23,000 --> 00:24:30,000
|
| 1259 |
+
event happens, when you separate different types of behavior, make sure you have separate Iraqi for
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:24:30,000 --> 00:24:35,000
|
| 1263 |
+
your subject with independent behavior and Iraqi observers with dependent behavior.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:24:36,000 --> 00:24:40,000
|
| 1267 |
+
Make sure that in observing interface you have method for notification.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:24:41,000 --> 00:24:43,000
|
| 1271 |
+
Subject my store references to observers.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:24:44,000 --> 00:24:47,000
|
| 1275 |
+
That is exactly why we created a list of observers.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:24:48,000 --> 00:24:55,000
|
| 1279 |
+
Observers should register themselves in subject, object subject, notifies all observers about event.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:24:55,000 --> 00:25:02,000
|
| 1283 |
+
When it happens, subject may push information to observers or let observers pool needed information
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:25:02,000 --> 00:25:02,000
|
| 1287 |
+
from subject.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:25:02,000 --> 00:25:09,000
|
| 1291 |
+
Object, that's it, we got an observer pardon, let's continue the next part is momentum.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:25:09,000 --> 00:25:14,000
|
| 1295 |
+
This is behavioral patterns that allow us to capture and store previous traits of the object.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:25:15,000 --> 00:25:19,000
|
| 1299 |
+
Having this information, we can easily return our object back to that state.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:25:19,000 --> 00:25:21,000
|
| 1303 |
+
Imagine Google Docs.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:25:21,000 --> 00:25:25,000
|
| 1307 |
+
If you have never worked with Google Docs, I will explain its cool feature.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:25:26,000 --> 00:25:30,000
|
| 1311 |
+
Google Docs source information literally about all changes in the document.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:25:31,000 --> 00:25:35,000
|
| 1315 |
+
And it doesn't matter if you would even close this document and close your browser at all.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:25:36,000 --> 00:25:42,000
|
| 1319 |
+
Any time you open this document again, you can browse the history of changes and restores the document
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:25:42,000 --> 00:25:46,000
|
| 1323 |
+
to its original state and how to solve this task on the court level.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:25:47,000 --> 00:25:52,000
|
| 1327 |
+
This is exactly why we need momentum part sometimes and how it is implemented and how to solve this
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:25:52,000 --> 00:25:53,000
|
| 1331 |
+
issue.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:25:53,000 --> 00:25:57,000
|
| 1335 |
+
Let's look at the court example to understand this sporran better.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:25:57,000 --> 00:26:01,000
|
| 1339 |
+
And by example, let's agree on the terminology first.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:26:01,000 --> 00:26:05,000
|
| 1343 |
+
The object whose state needs to be saved is called an originator.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:26:06,000 --> 00:26:08,000
|
| 1347 |
+
Also, we have so-called caretake.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:26:09,000 --> 00:26:09,000
|
| 1351 |
+
What is that?
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:26:10,000 --> 00:26:15,000
|
| 1355 |
+
The caretaker is the object that triggers a safe and restore of the state.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:26:15,000 --> 00:26:19,000
|
| 1359 |
+
The state is encapsulated in object that is called the momentum.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:26:20,000 --> 00:26:25,000
|
| 1363 |
+
The momentum object should expose as little information as possible to the caretaker.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:26:26,000 --> 00:26:32,000
|
| 1367 |
+
This is to ensure that we don't expose internal state of the originator to the outside world as it would
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:26:32,000 --> 00:26:34,000
|
| 1371 |
+
break encapsulation principle.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:26:34,000 --> 00:26:40,000
|
| 1375 |
+
However, the originator should access enough information in order to restore the original state.
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:26:41,000 --> 00:26:47,000
|
| 1379 |
+
When we talk about originator, it is worth to say that it can produce and consume and amend the object.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:26:47,000 --> 00:26:52,000
|
| 1383 |
+
At the meantime, caretaker keeps the state before storing it.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:26:53,000 --> 00:26:59,000
|
| 1387 |
+
It is often happens that having one field is more than enough to represent the state of the originator.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:26:59,000 --> 00:27:05,000
|
| 1391 |
+
But we are not limited to one field only and the states that will keep in mind the object shouldn't
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:27:05,000 --> 00:27:09,000
|
| 1395 |
+
march to the complete state of the originator object on one hundred percent.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:27:09,000 --> 00:27:15,000
|
| 1399 |
+
As long as we keep on the information needed to restore the state of the originator, we are not in
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:27:16,000 --> 00:27:16,000
|
| 1403 |
+
this.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:27:16,000 --> 00:27:20,000
|
| 1407 |
+
Let's decide what clause will perform the role of originate the object.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:27:21,000 --> 00:27:22,000
|
| 1411 |
+
We have three main classes here.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:27:23,000 --> 00:27:27,000
|
| 1415 |
+
They are text window, text editor and text.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:27:27,000 --> 00:27:34,000
|
| 1419 |
+
When those state text window is our originator clause, we want to store states of object of this type.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:27:34,000 --> 00:27:39,000
|
| 1423 |
+
It consists from string builder that work with strings that we pass to this object.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:27:40,000 --> 00:27:46,000
|
| 1427 |
+
The safe method of this class creates an object of text in those state type and restore method.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:27:46,000 --> 00:27:52,000
|
| 1431 |
+
Initialized text in window field was the states that will pass as a method argument.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:27:53,000 --> 00:27:55,000
|
| 1435 |
+
Text editor is our caretake.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:27:55,000 --> 00:28:01,000
|
| 1439 |
+
A class object of this type will be in charge of saving state of the text window and restoring its state.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:28:02,000 --> 00:28:05,000
|
| 1443 |
+
And you can see that to perform such operations.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:28:05,000 --> 00:28:07,000
|
| 1447 |
+
We have a list of text in those states.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:28:08,000 --> 00:28:15,000
|
| 1451 |
+
We can save state of text window and added to the list by calling Save Method and we can restore state
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:28:15,000 --> 00:28:21,000
|
| 1455 |
+
of the text window by snapshot index directly from our O'Reilley text window.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:28:21,000 --> 00:28:28,000
|
| 1459 |
+
State class is the basis for our momentum objects and as you can see, it doesn't source to build a
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:28:28,000 --> 00:28:29,000
|
| 1463 |
+
text window.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:28:29,000 --> 00:28:34,000
|
| 1467 |
+
It stores just enough information to restore the state of the text window.
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:28:34,000 --> 00:28:40,000
|
| 1471 |
+
Basically the strings that will be used to initialize the variable of string builder type inside the
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:28:40,000 --> 00:28:44,000
|
| 1475 |
+
text when the object is that clear how bad it is.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:28:44,000 --> 00:28:46,000
|
| 1479 |
+
Let's now look at the demo class.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:28:47,000 --> 00:28:49,000
|
| 1483 |
+
I will run this file to explore console output.
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:28:49,000 --> 00:28:55,000
|
| 1487 |
+
Together with you, I create object of text editor type and object of window type.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:28:56,000 --> 00:29:01,000
|
| 1491 |
+
I call write method on text window, object to write some text into the window.
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:29:01,000 --> 00:29:08,000
|
| 1495 |
+
I call the same method with another text one more time inside text window object and just append new
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:29:08,000 --> 00:29:13,000
|
| 1499 |
+
text already existing one using all features of string builder object.
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:29:13,000 --> 00:29:21,000
|
| 1503 |
+
After that I call safe method on my text editor and I pass that text window state object that is returned
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:29:21,000 --> 00:29:23,000
|
| 1507 |
+
by calling safe method on text window.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:29:24,000 --> 00:29:25,000
|
| 1511 |
+
That would be my first snapshot.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:29:26,000 --> 00:29:30,000
|
| 1515 |
+
After that I write additional text and save the state one more time.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:29:30,000 --> 00:29:32,000
|
| 1519 |
+
This is my second snapshot.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:29:33,000 --> 00:29:38,000
|
| 1523 |
+
Now I print state of text window to consult first time and we see all three lines.
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:29:39,000 --> 00:29:44,000
|
| 1527 |
+
After that I print, separate the lines and restore the previous state how I can do it.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:29:45,000 --> 00:29:49,000
|
| 1531 |
+
I call restore method on my text mindo object and parse that text.
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:29:49,000 --> 00:29:56,000
|
| 1535 |
+
When the state object that is returned by Massata annotation on text editor class I call get state by
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:29:56,000 --> 00:30:02,000
|
| 1539 |
+
Slapshot Index method and parse the index of the snapshot if I want to give the first snapshot.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:30:02,000 --> 00:30:10,000
|
| 1543 |
+
I will pass in the case of zero April tax to console, and you can see this is exactly the state that
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:30:10,000 --> 00:30:15,000
|
| 1547 |
+
I had after first saving the last line and it was a separator.
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:30:15,000 --> 00:30:17,000
|
| 1551 |
+
That's why I have this tax.
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:30:17,000 --> 00:30:24,000
|
| 1555 |
+
And now I would like to do a redo operation and just restore the state of my second snapshot and bring
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:30:24,000 --> 00:30:25,000
|
| 1559 |
+
tax to consult one more time.
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:30:26,000 --> 00:30:31,000
|
| 1563 |
+
Is it clear and in real life you may have different versions of the same idea.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:30:31,000 --> 00:30:37,000
|
| 1567 |
+
For example, you may have masses and do and will do instead of having a method of getting inception
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:30:37,000 --> 00:30:39,000
|
| 1571 |
+
by index, that is also possible.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:30:39,000 --> 00:30:43,000
|
| 1575 |
+
The main thing is to follow the main idea I've just described.
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:30:43,000 --> 00:30:50,000
|
| 1579 |
+
I recommend you to pull these good examples from my git repository and run this example on your local
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:30:50,000 --> 00:30:50,000
|
| 1583 |
+
computer.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:30:51,000 --> 00:30:57,000
|
| 1587 |
+
It will give you an opportunity to understand better how this court works, lets you use a checklist
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:30:57,000 --> 00:31:04,000
|
| 1591 |
+
to implement moment upon identify and split rules of originator and caretake between classes.
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:31:04,000 --> 00:31:11,000
|
| 1595 |
+
Create momentum type that contains enough information to restore originator object, caretake store
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:31:11,000 --> 00:31:17,000
|
| 1599 |
+
information about all states of originator and knows how to save and restore State of Origin.
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:31:17,000 --> 00:31:24,000
|
| 1603 |
+
If the object originator object may create momentum, objects originate and instantiate itself using
|
| 1604 |
+
|
| 1605 |
+
402
|
| 1606 |
+
00:31:24,000 --> 00:31:26,000
|
| 1607 |
+
Safet state in the manner to object.
|
| 1608 |
+
|
| 1609 |
+
403
|
| 1610 |
+
00:31:27,000 --> 00:31:30,000
|
| 1611 |
+
Hope you learned a lot of interesting things about momentum.
|
| 1612 |
+
|
| 1613 |
+
404
|
| 1614 |
+
00:31:31,000 --> 00:31:34,000
|
| 1615 |
+
Now let's recap what we have learned today.
|
| 1616 |
+
|
| 1617 |
+
405
|
| 1618 |
+
00:31:34,000 --> 00:31:37,000
|
| 1619 |
+
In this lesson we learned such behavioral patterns.
|
| 1620 |
+
|
| 1621 |
+
406
|
| 1622 |
+
00:31:37,000 --> 00:31:41,000
|
| 1623 |
+
Visiter, State, Observer and the Mantha.
|
| 1624 |
+
|
| 1625 |
+
407
|
| 1626 |
+
00:31:41,000 --> 00:31:42,000
|
| 1627 |
+
That's it for today.
|
| 1628 |
+
|
| 1629 |
+
408
|
| 1630 |
+
00:31:43,000 --> 00:31:44,000
|
| 1631 |
+
Thanks a lot for your attention.
|
| 1632 |
+
|
| 1633 |
+
409
|
| 1634 |
+
00:31:45,000 --> 00:31:47,000
|
| 1635 |
+
Have a great day and see you in the next lesson.
|
| 1636 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/006 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
39 - GoF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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:10,000
|
| 3 |
+
Hello, dear students, by this moment and now, of course, we learned really a lot of behavioral golf,
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:18,000
|
| 7 |
+
Gulfport's to be specific and previous lessons, I explained unan behavioral patterns, but this means
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:18,000 --> 00:00:20,000
|
| 11 |
+
that we still have two more points to learn.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:20,000 --> 00:00:23,000
|
| 15 |
+
That is exactly what we are going to do in this lesson.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:23,000 --> 00:00:27,000
|
| 19 |
+
We're going to learn last but not the least, behavioral patterns.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:31,000
|
| 23 |
+
And as you already understood, we have only two behavioral patterns left.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:32,000 --> 00:00:39,000
|
| 27 |
+
They are interpretor and mydata source code examples for each part in attachments to this Lassy.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:40,000 --> 00:00:43,000
|
| 31 |
+
We will review those examples together during the lesson.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:43,000 --> 00:00:49,000
|
| 35 |
+
But still, it is a good idea to run these examples locally on your computer to understand these patterns
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:49,000 --> 00:00:49,000
|
| 39 |
+
better.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:49,000 --> 00:00:57,000
|
| 43 |
+
Let's start we'll start from Interpretor Barton and to explain in simple words what Interpreter Point
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:57,000 --> 00:00:59,000
|
| 47 |
+
is, let me start from small example.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:00,000 --> 00:01:03,000
|
| 51 |
+
Imagine compiler, whatever compiler you can imagine.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:03,000 --> 00:01:10,000
|
| 55 |
+
For example, Java compiler compiler transforms code written in high level programming language into
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:10,000 --> 00:01:14,000
|
| 59 |
+
the machine code at once before program runs.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:14,000 --> 00:01:20,000
|
| 63 |
+
So you have some language that you don't want to translate by itself each time you need to run Java
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:20,000 --> 00:01:27,000
|
| 67 |
+
program on Gibeah for such purposes, you have compiler that does this work for you and translate high
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:27,000 --> 00:01:30,000
|
| 71 |
+
level programming language into machine code.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:30,000 --> 00:01:33,000
|
| 75 |
+
This is one of use cases of using interpretor.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:34,000 --> 00:01:39,000
|
| 79 |
+
This pardon is used to define the description of the grammar of the interpreted language.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:39,000 --> 00:01:45,000
|
| 83 |
+
This pattern allows us technically to implement custom regular expressions, language or custom domain
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:45,000 --> 00:01:47,000
|
| 87 |
+
specific language interpreter.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:47,000 --> 00:01:51,000
|
| 91 |
+
Or we can create interpreters that would pass human languages.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:51,000 --> 00:01:53,000
|
| 95 |
+
We can find even more use cases.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:54,000 --> 00:01:58,000
|
| 99 |
+
For example, your integrated development environment, your idea.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:58,000 --> 00:02:04,000
|
| 103 |
+
It constantly analyzes and interprets the code as we type in the new words in our text editor.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:04,000 --> 00:02:11,000
|
| 107 |
+
And this allows it to provide us with hints and on the basis of our code, even before code compilation
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:11,000 --> 00:02:12,000
|
| 111 |
+
and execution.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:12,000 --> 00:02:18,000
|
| 115 |
+
But definitely we should keep in mind that we can successfully apply this pattern when the grammar is
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:18,000 --> 00:02:19,000
|
| 119 |
+
relatively simple.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:20,000 --> 00:02:24,000
|
| 123 |
+
Let's now quickly discuss how this pardon is implemented in this part.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:24,000 --> 00:02:26,000
|
| 127 |
+
And we have two main entities.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:26,000 --> 00:02:29,000
|
| 131 |
+
They are context and expression.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:29,000 --> 00:02:37,000
|
| 135 |
+
This will allow us to do two things describe any word expression and define meaning of such expressions.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:37,000 --> 00:02:38,000
|
| 139 |
+
In specific contexts.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:39,000 --> 00:02:45,000
|
| 143 |
+
We describe abstract expressions that usually have one method that is called interpret the takes context
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:45,000 --> 00:02:47,000
|
| 147 |
+
as Masad argument.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:47,000 --> 00:02:54,000
|
| 151 |
+
This will allow for each expression to affect the context by saying affect the context, I mean change
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:54,000 --> 00:02:59,000
|
| 155 |
+
its state continuous interpretation or just return a result.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:59,000 --> 00:03:05,000
|
| 159 |
+
That means that we should have context class that will be considered as holder of global state of processing
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:06,000 --> 00:03:11,000
|
| 163 |
+
and it will be used by different elements, different interpretation, process, abstract expression
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:11,000 --> 00:03:14,000
|
| 167 |
+
might be extended by two other types.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:14,000 --> 00:03:18,000
|
| 171 |
+
They are terminal and then terminal expressions.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:18,000 --> 00:03:23,000
|
| 175 |
+
I believe that on the high level it is clear what is the difference between these two types considering
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:23,000 --> 00:03:24,000
|
| 179 |
+
their names.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:25,000 --> 00:03:27,000
|
| 183 |
+
But let's make sure that we are on the same page.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:28,000 --> 00:03:32,000
|
| 187 |
+
Terminal expression is a final expression in the interpretation process.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:32,000 --> 00:03:38,000
|
| 191 |
+
None terminal expression usually has the reference to the next expression to proceed interpretation
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:38,000 --> 00:03:39,000
|
| 195 |
+
process.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:39,000 --> 00:03:41,000
|
| 199 |
+
It is similar to streams in Java.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:41,000 --> 00:03:47,000
|
| 203 |
+
You have terminal methods and non terminal and only terminal expression can finish interpretation process.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:48,000 --> 00:03:49,000
|
| 207 |
+
By the way, there.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:49,000 --> 00:03:51,000
|
| 211 |
+
Remember such structural partners composite.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:52,000 --> 00:03:54,000
|
| 215 |
+
Let me just remind you what that pattern is about.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:55,000 --> 00:04:01,000
|
| 219 |
+
Composite is a structural pattern that allows us to interact with a single object, always group of
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:01,000 --> 00:04:03,000
|
| 223 |
+
objects with the help of a single interface.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:04,000 --> 00:04:09,000
|
| 227 |
+
And often expressions are composite objects that encapsulate different expressions.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:09,000 --> 00:04:12,000
|
| 231 |
+
But we interact with expression as we single one.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:13,000 --> 00:04:16,000
|
| 235 |
+
The role of the client is to create an abstract syntax tree.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:16,000 --> 00:04:20,000
|
| 239 |
+
But what is an abstract syntax tree in computer science?
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:20,000 --> 00:04:29,000
|
| 243 |
+
Abstract syntax tree shortened version of this is a a S.T. or just syntax tree is a tree representation
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:29,000 --> 00:04:30,000
|
| 247 |
+
of sorts cost structure.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:31,000 --> 00:04:35,000
|
| 251 |
+
Each north of tree denotes a construct occurring in the source code.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:35,000 --> 00:04:37,000
|
| 255 |
+
It is called abstract syntax.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:37,000 --> 00:04:43,000
|
| 259 |
+
Three because this syntax doesn't represent all the details appear in real syntax.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:43,000 --> 00:04:50,000
|
| 263 |
+
Abstract syntax trees are data structures widely used in compilers to represent the structure of program
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:50,000 --> 00:04:58,000
|
| 267 |
+
code, and ACG is usually a result of the syntax analysis phase of a compiler coming back to the client
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:58,000 --> 00:05:01,000
|
| 271 |
+
code responsibilities, rephrasing it in simple words.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:01,000 --> 00:05:03,000
|
| 275 |
+
Clients should build three of.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:03,000 --> 00:05:09,000
|
| 279 |
+
Rations that will be used in interpretation homes, and this is clear now.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:09,000 --> 00:05:15,000
|
| 283 |
+
And as always, I believe that a good example worth a thousand words, let's review the source code
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:15,000 --> 00:05:17,000
|
| 287 |
+
examples that I prepared for today.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:18,000 --> 00:05:23,000
|
| 291 |
+
This is not the easiest part to understand, but I will try to explain it to you as examples.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:23,000 --> 00:05:28,000
|
| 295 |
+
I have two examples here, simple and more or less real life closed.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:29,000 --> 00:05:33,000
|
| 299 |
+
Let's start from the simple one that is located in this demo.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:33,000 --> 00:05:38,000
|
| 303 |
+
One package we have expression interface that declares only one method.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:38,000 --> 00:05:45,000
|
| 307 |
+
Interpret the text, interpret interpretation context as method argument and returns string value.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:45,000 --> 00:05:48,000
|
| 311 |
+
Let's now look at interpretor context.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:48,000 --> 00:05:50,000
|
| 315 |
+
This class has only two methods.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:50,000 --> 00:05:55,000
|
| 319 |
+
They are yet binary format and got hexadecimal format.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:55,000 --> 00:06:02,000
|
| 323 |
+
And I believe you can see that we use basic behavior from integer class to convert in into different
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:02,000 --> 00:06:03,000
|
| 327 |
+
formats.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:03,000 --> 00:06:10,000
|
| 331 |
+
Also, we have two implementations of expression interface layer into binary expression and intersex
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:10,000 --> 00:06:11,000
|
| 335 |
+
expression.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:12,000 --> 00:06:18,000
|
| 339 |
+
As you can see these expressions to interpret the context as Masset argument and just use it to perform
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:18,000 --> 00:06:21,000
|
| 343 |
+
request that the operation take into account.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:21,000 --> 00:06:24,000
|
| 347 |
+
We have to store in somewhere to perform the separation.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:24,000 --> 00:06:25,000
|
| 351 |
+
We pass it.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:25,000 --> 00:06:31,000
|
| 355 |
+
We are constructor and use it later in this method when we invoke method of interpretive context.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:32,000 --> 00:06:34,000
|
| 359 |
+
So these two classes are similar.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:34,000 --> 00:06:38,000
|
| 363 |
+
Tsong The difference is a method that we invoke and interpret the context object.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:39,000 --> 00:06:42,000
|
| 367 |
+
Now let's look at the client code and our demo class.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:43,000 --> 00:06:48,000
|
| 371 |
+
We have here interpret mass that basically describes kind of abstract syntax.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:48,000 --> 00:06:55,000
|
| 375 |
+
Three kind of basically this method contains information how to parse string in case it contains is
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:55,000 --> 00:06:57,000
|
| 379 |
+
that small string of binary string.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:58,000 --> 00:07:03,000
|
| 383 |
+
Depending on this, we initialize our expression variable and perform, interpret Masset on it.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:04,000 --> 00:07:08,000
|
| 387 |
+
In our main mass, we have two strings that are started with numbers.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:08,000 --> 00:07:14,000
|
| 391 |
+
We create an object of our client code and we print the console result of interpretation.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:14,000 --> 00:07:22,000
|
| 395 |
+
Is that clear my code, evaluate the expression and understand when it needs to convert number from
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:22,000 --> 00:07:25,000
|
| 399 |
+
the phrase the binary hexadecimal format.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:26,000 --> 00:07:29,000
|
| 403 |
+
Press a pause for a minute and think about this example.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:29,000 --> 00:07:36,000
|
| 407 |
+
I also encourage you to download the source code of this program and run it locally on your computer.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:36,000 --> 00:07:42,000
|
| 411 |
+
And I know that this example is oversimplified, but it is good to start with.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:42,000 --> 00:07:44,000
|
| 415 |
+
Agree why I said that?
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:44,000 --> 00:07:51,000
|
| 419 |
+
It is oversimplified in my opinion because we don't have long term channel and channel expressions combined
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:51,000 --> 00:07:58,000
|
| 423 |
+
together and brought us together, because definitely there is a specific sort of heaven on channel
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:58,000 --> 00:08:01,000
|
| 427 |
+
and terminal expressions and interprets syntax.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:01,000 --> 00:08:08,000
|
| 431 |
+
We have over simplified syntax and room for interpretation here because in real life, syntax for interpretation
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:08,000 --> 00:08:10,000
|
| 435 |
+
might be a little bit more complex.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:10,000 --> 00:08:15,000
|
| 439 |
+
OK, if you think that this example is clear for you, let's check another one.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:16,000 --> 00:08:19,000
|
| 443 |
+
Number two, it is more complex than previous one.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:20,000 --> 00:08:21,000
|
| 447 |
+
Let me start from the demo file.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:22,000 --> 00:08:24,000
|
| 451 |
+
Imagine that we have these objects.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:25,000 --> 00:08:28,000
|
| 455 |
+
Some of them represents engineers, some of the managers.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:28,000 --> 00:08:35,000
|
| 459 |
+
All of them are united with abstract class employee that serves as an abstraction for these types.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:35,000 --> 00:08:40,000
|
| 463 |
+
Each employee is in some of the departments, has some title and salary.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:41,000 --> 00:08:44,000
|
| 467 |
+
All employees also have their personal iji inside the company.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:45,000 --> 00:08:47,000
|
| 471 |
+
We have a limited number of departments.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:47,000 --> 00:08:50,000
|
| 475 |
+
That's why we have departments as in them here.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:51,000 --> 00:08:57,000
|
| 479 |
+
Each engineer has manager and that's why we are Mappin engineers and managers here.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:57,000 --> 00:08:59,000
|
| 483 |
+
And here's our first context.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:59,000 --> 00:09:04,000
|
| 487 |
+
For example, this is my own domain specific language that I introduced in this example.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:05,000 --> 00:09:10,000
|
| 491 |
+
I described this as a nation department whom he manages and what is his salary.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:11,000 --> 00:09:17,000
|
| 495 |
+
I expect to be able to get true or false in process of interpretation of this drink was my context.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:18,000 --> 00:09:25,000
|
| 499 |
+
I will pass the reference to my employee and want to get is a true or false true in case my employee
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:25,000 --> 00:09:29,000
|
| 503 |
+
matches this requirements and false if doesn't.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:29,000 --> 00:09:35,000
|
| 507 |
+
The goal of this app is to verify an employee against this set of requirements.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:35,000 --> 00:09:36,000
|
| 511 |
+
Let me run this app.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:37,000 --> 00:09:41,000
|
| 515 |
+
I create expression in the next line how I do that.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:41,000 --> 00:09:46,000
|
| 519 |
+
I call part expression method on my object and pass in context.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:46,000 --> 00:09:54,000
|
| 523 |
+
Think there in this method I split all string by comma and after that have key value pairs divided by
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:54,000 --> 00:09:55,000
|
| 527 |
+
semicolon.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:55,000 --> 00:09:59,000
|
| 531 |
+
I am split in this and create new expression by column get expression.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:00,000 --> 00:10:07,000
|
| 535 |
+
And you can see here that once I initialised expression available, I create an expression to collect
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:07,000 --> 00:10:09,000
|
| 539 |
+
original expression and allows X.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:10,000 --> 00:10:16,000
|
| 543 |
+
And create a composite object, all expressions in this example are stored in a separate package with
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:16,000 --> 00:10:22,000
|
| 547 |
+
the name expression's, the main types here are expression, interface, luncheon, terminal expression,
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:22,000 --> 00:10:29,000
|
| 551 |
+
abstract class and terminal, abstract class that extends expression and expression interface, which
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:29,000 --> 00:10:32,000
|
| 555 |
+
is the main mass that each expression should implement.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:32,000 --> 00:10:38,000
|
| 559 |
+
Pay attention that in this case, employee object will perform a role of interpretation, context,
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:39,000 --> 00:10:42,000
|
| 563 |
+
and in this example, interpret Masset returns.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:42,000 --> 00:10:44,000
|
| 567 |
+
Boolean value is a true or false.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:45,000 --> 00:10:47,000
|
| 571 |
+
Now let's open none terminal expression.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:48,000 --> 00:10:51,000
|
| 575 |
+
You can see here we have the reference to another expression.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:52,000 --> 00:10:56,000
|
| 579 |
+
That is because the terminal expression always has an expression linked to it.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:57,000 --> 00:11:04,000
|
| 583 |
+
We have a lot of expressions listed here and to not perform review of all of them, like an open source
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:04,000 --> 00:11:06,000
|
| 587 |
+
code of an expression is interesting.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:06,000 --> 00:11:11,000
|
| 591 |
+
What we can see that we have left and right expression here.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:11,000 --> 00:11:17,000
|
| 595 |
+
I believe that you learned composite part well, and you can understand, since the left and right expression
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:17,000 --> 00:11:22,000
|
| 599 |
+
also can be an expression that also consists of different expressions.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:23,000 --> 00:11:25,000
|
| 603 |
+
We have different variations of expressions.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:25,000 --> 00:11:32,000
|
| 607 |
+
For example, manager of expression, name, expression, department expression and lots more.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:32,000 --> 00:11:36,000
|
| 611 |
+
One of them contains the logic described in interpret method.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:36,000 --> 00:11:38,000
|
| 615 |
+
Let's get back to our demo file.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:39,000 --> 00:11:46,000
|
| 619 |
+
And after I created my composite object, my expression, I print context, trying to console that new
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:46,000 --> 00:11:46,000
|
| 623 |
+
line.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:46,000 --> 00:11:49,000
|
| 627 |
+
Then I print my manager and try to cancel.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:50,000 --> 00:11:56,000
|
| 631 |
+
And after that I format the string to represent the expression that I received after passing the contact
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:56,000 --> 00:12:00,000
|
| 635 |
+
string and result of interpretation for rate as a context.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:01,000 --> 00:12:04,000
|
| 639 |
+
And we see that the answer is true indeed.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:05,000 --> 00:12:09,000
|
| 643 |
+
And managers are tone and has the salary like in our example here.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:10,000 --> 00:12:10,000
|
| 647 |
+
Is that clear?
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:11,000 --> 00:12:13,000
|
| 651 |
+
Next examples are pretty similar.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:13,000 --> 00:12:19,000
|
| 655 |
+
But just to make you understand that I can use different characters and symbols in my domain specific
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:19,000 --> 00:12:20,000
|
| 659 |
+
language.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:20,000 --> 00:12:26,000
|
| 663 |
+
For example, in this case we need to find a developer who is an engineering department and has salary
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:26,000 --> 00:12:28,000
|
| 667 |
+
less than eighty five thousand.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:29,000 --> 00:12:31,000
|
| 671 |
+
And in the case was our term.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:31,000 --> 00:12:38,000
|
| 675 |
+
We received true when we interpreted this expression in this specific context and with the same expression,
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:38,000 --> 00:12:39,000
|
| 679 |
+
I got false.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:39,000 --> 00:12:46,000
|
| 683 |
+
If I pass Aleksi as a context because Aleksei is a developer, but with higher salary higher than in
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:46,000 --> 00:12:51,000
|
| 687 |
+
our condition, basically that is how interpreter partner works.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:51,000 --> 00:12:58,000
|
| 691 |
+
And I means that this example is not the easiest one, but it is nothing more to share and just encourage
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:12:58,000 --> 00:13:04,000
|
| 695 |
+
you to run the source code in your local computer to understand how this code works and the bogert if
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:04,000 --> 00:13:04,000
|
| 699 |
+
needed.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:05,000 --> 00:13:10,000
|
| 703 |
+
I believe that after sitting at most ten minutes with this example and probably watching my explanations
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:10,000 --> 00:13:14,000
|
| 707 |
+
one more time, everything will become crystal clear for you.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:14,000 --> 00:13:20,000
|
| 711 |
+
Reference to code examples in attachments to this lesson, I believe the demo helps you to understand
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:20,000 --> 00:13:22,000
|
| 715 |
+
interpret upon them better.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:22,000 --> 00:13:27,000
|
| 719 |
+
But now let's try to sum it up and create a checklist to implement interpretive parren.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:28,000 --> 00:13:33,000
|
| 723 |
+
The first thing you need to do is to define a grammar for language that you want to interpret.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:33,000 --> 00:13:40,000
|
| 727 |
+
After that map, each production in the grammar to a class then organize this use of grammar classes
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:40,000 --> 00:13:42,000
|
| 731 |
+
into the structure of the composite palm.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:43,000 --> 00:13:48,000
|
| 735 |
+
In our example, it was expression, type, define and interpret MassArt.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:48,000 --> 00:13:50,000
|
| 739 |
+
That takes context as a parameter in the composite.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:50,000 --> 00:13:56,000
|
| 743 |
+
The Iraqi, the context object encapsulates the current state of the input and output.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:13:57,000 --> 00:14:05,000
|
| 747 |
+
It is affected by each grammar class as interpreting process transforms the input into the output that
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:05,000 --> 00:14:05,000
|
| 751 |
+
sets.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:05,000 --> 00:14:06,000
|
| 755 |
+
We got an interpreter pattern.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:07,000 --> 00:14:11,000
|
| 759 |
+
Let's proceed with the next button and the next part is a mediator.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:12,000 --> 00:14:18,000
|
| 763 |
+
The main goal of Mediator Parren is to reduce the coupling between the classes and put all logic that
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:18,000 --> 00:14:22,000
|
| 767 |
+
is related to the interaction between different classes in another separate class.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:22,000 --> 00:14:28,000
|
| 771 |
+
In this case, different objects don't interact explicitly between each other.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:28,000 --> 00:14:33,000
|
| 775 |
+
But instead of this mediator, object controls interaction between them.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:33,000 --> 00:14:37,000
|
| 779 |
+
That's why this is considered to be a good practice in Obed design.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:37,000 --> 00:14:44,000
|
| 783 |
+
We should always try to design the system in such a way that components are loosely coupled and reuseable.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:44,000 --> 00:14:50,000
|
| 787 |
+
Imagines that you're an admin of your web platform and you have a pop up dialogue to create a new user
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:50,000 --> 00:14:51,000
|
| 791 |
+
in your system.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:52,000 --> 00:14:59,000
|
| 795 |
+
And this dialogue contains different text, fields, buttons, checkboxes, and all these elements should
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:14:59,000 --> 00:15:00,000
|
| 799 |
+
interact between each other.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:01,000 --> 00:15:07,000
|
| 803 |
+
For example, if you are selecting checkbox, a new employee wants to get relocated to another country,
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:07,000 --> 00:15:09,000
|
| 807 |
+
then we need to show new.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:09,000 --> 00:15:15,000
|
| 811 |
+
That contains rubdown with a list of countries for possible relocation, and in case we would put this
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:15,000 --> 00:15:21,000
|
| 815 |
+
logic in checkbox, this will not allow us to use this checkbook's in other places, because from now
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:21,000 --> 00:15:25,000
|
| 819 |
+
on, this checkbox will work only with this dropdown list.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:26,000 --> 00:15:33,000
|
| 823 |
+
But we need to think how we will scale our code in the future, because this might end up with us being
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:33,000 --> 00:15:38,000
|
| 827 |
+
able to use behavior of these animals on the inside to create user dialogue.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:38,000 --> 00:15:42,000
|
| 831 |
+
And it will be hard to use these animals in other dialogues if needed.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:43,000 --> 00:15:49,000
|
| 835 |
+
The solution of this would be introducing a mediator pardon that's supposed to solve the issue of tight
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:49,000 --> 00:15:51,000
|
| 839 |
+
coupling of components between each other.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:52,000 --> 00:15:57,000
|
| 843 |
+
We'll have separate classes that will be in charge of redirecting the request between the elements.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:58,000 --> 00:16:04,000
|
| 847 |
+
This class is a mediator class by encapsulating all complicated connections and interactions between
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:04,000 --> 00:16:07,000
|
| 851 |
+
different types with decrease Coplin between classes.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:08,000 --> 00:16:15,000
|
| 855 |
+
And we know that unless Coplan then more reusable components we have and mediate in this case performs
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:15,000 --> 00:16:18,000
|
| 859 |
+
and orchestration of other elements.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:18,000 --> 00:16:25,000
|
| 863 |
+
I believe that you already understood what Mediate A is on the high level and what problems is supposed
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:25,000 --> 00:16:27,000
|
| 867 |
+
to solve the Lanzas foreign matter.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:27,000 --> 00:16:34,000
|
| 871 |
+
Let's look at the good example in this example will implement with due process of trying TV on and training
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:34,000 --> 00:16:38,000
|
| 875 |
+
TV off with the help of the one button on our remote control.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:39,000 --> 00:16:42,000
|
| 879 |
+
Let me start the demo from the client code.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:42,000 --> 00:16:44,000
|
| 883 |
+
I opened them a class.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:44,000 --> 00:16:47,000
|
| 887 |
+
I ran the file to Explorer console output together with you.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:48,000 --> 00:16:52,000
|
| 891 |
+
The first thing that I do, I create mediator object.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:52,000 --> 00:16:57,000
|
| 895 |
+
After that I create the object object of a button type and TV display.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:58,000 --> 00:17:01,000
|
| 899 |
+
I link all these types with the help of mediator.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:01,000 --> 00:17:07,000
|
| 903 |
+
As you can see, I pass in reference to the mediator, object to constructor of each object here and
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:07,000 --> 00:17:13,000
|
| 907 |
+
then use setters to pass the reference to give and display objects to my mediator object.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:13,000 --> 00:17:14,000
|
| 911 |
+
Great.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:14,000 --> 00:17:19,000
|
| 915 |
+
Now all objects know about mediator and mediator knows about all objects.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:19,000 --> 00:17:25,000
|
| 919 |
+
Before I start to do any manipulations, I print the original state of my TV to consult.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:25,000 --> 00:17:27,000
|
| 923 |
+
Let me open a TV class here.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:27,000 --> 00:17:35,000
|
| 927 |
+
We can see that state of TV is described with the help of mediator type and is on type is on is just
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:35,000 --> 00:17:39,000
|
| 931 |
+
a Google flag to indicate whether the TV is on or off.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:40,000 --> 00:17:41,000
|
| 935 |
+
Let's get back to our demo file.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:42,000 --> 00:17:45,000
|
| 939 |
+
After that, I perform my first action.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:45,000 --> 00:17:47,000
|
| 943 |
+
I press the button on my remote control.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:17:48,000 --> 00:17:52,000
|
| 947 |
+
Let's investigate the source code of press method as other types.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:17:52,000 --> 00:17:56,000
|
| 951 |
+
My button type keeps the reference to the mediator object.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:17:56,000 --> 00:18:02,000
|
| 955 |
+
And instead of sending a request directly to TV object or to display, I am sending request the mediator
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:02,000 --> 00:18:07,000
|
| 959 |
+
object that gives me opportunity to not burn this button.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:07,000 --> 00:18:14,000
|
| 963 |
+
Type two TV only probably I have also air conditioning or I have something else in my apartment and
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:14,000 --> 00:18:20,000
|
| 967 |
+
I can reuse this type of model in other cases with the help of different mediators if needed.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:20,000 --> 00:18:28,000
|
| 971 |
+
Now let's go to the mediator object and explore this press Masset Press Masad checks if TV is on or
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:28,000 --> 00:18:36,000
|
| 975 |
+
off and basically if TV is off, we are turning it on and if TV is on, we are turning it off.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:36,000 --> 00:18:41,000
|
| 979 |
+
The logic is pretty simple here and I interact with TV objects through the media to type.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:42,000 --> 00:18:44,000
|
| 983 |
+
Let me open key type here.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:44,000 --> 00:18:50,000
|
| 987 |
+
We can see the turn on and turn off masses also interact with the mediator object.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:18:50,000 --> 00:18:56,000
|
| 991 |
+
Obviously I change the state of TV itself, but also I need to channel display on.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:18:57,000 --> 00:19:01,000
|
| 995 |
+
But again, I don't interact with any display object directly.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:02,000 --> 00:19:04,000
|
| 999 |
+
I'm sending request back to mydata object.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:05,000 --> 00:19:07,000
|
| 1003 |
+
Let's see how these masses are implemented.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:08,000 --> 00:19:10,000
|
| 1007 |
+
I'm talking about start and stop masses.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:11,000 --> 00:19:15,000
|
| 1011 |
+
So these masses just delegates are called to the display object and that's it.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:16,000 --> 00:19:22,000
|
| 1015 |
+
And finally, if we would open display object, we can see that we just print text to console when displays
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:22,000 --> 00:19:26,000
|
| 1019 |
+
on or display is off and no other interactions.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:26,000 --> 00:19:33,000
|
| 1023 |
+
But still, you might pass me to the constructor and work with me later to send request to other objects
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:33,000 --> 00:19:33,000
|
| 1027 |
+
if needed.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:19:34,000 --> 00:19:34,000
|
| 1031 |
+
Is that clear?
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:35,000 --> 00:19:40,000
|
| 1035 |
+
If yes, then let's get back to the demo file and we'll review console output.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:19:40,000 --> 00:19:47,000
|
| 1039 |
+
As you can see that after I pressed the button, I see the display is on now and state of the TV is
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:19:47,000 --> 00:19:48,000
|
| 1043 |
+
changed to.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:19:48,000 --> 00:19:56,000
|
| 1047 |
+
And when I press the power button again, the display is turned off and TV is off to does it make sense?
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:19:56,000 --> 00:20:02,000
|
| 1051 |
+
Recommended to run this code on your local machine to explore how objects interact with each other.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:03,000 --> 00:20:08,000
|
| 1055 |
+
Now let's review steps to implement, mediate apart and identify a group of classes that we want.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:09,000 --> 00:20:15,000
|
| 1059 |
+
The couple created new abstraction and encapsulate all interactions inside a new class mydata class,
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:16,000 --> 00:20:20,000
|
| 1063 |
+
and it all exists in classes to make them interact with mydata object only.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:21,000 --> 00:20:22,000
|
| 1067 |
+
That's it.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:22,000 --> 00:20:23,000
|
| 1071 |
+
In my opinion.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:23,000 --> 00:20:28,000
|
| 1075 |
+
This is relatively simple patterns that will help us to reduce carbon between our classes.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:29,000 --> 00:20:31,000
|
| 1079 |
+
Now, let's check what we have learned today.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:31,000 --> 00:20:34,000
|
| 1083 |
+
In this lesson we learned to patterns.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:34,000 --> 00:20:40,000
|
| 1087 |
+
They are interpretor and mydata part, and this is part of learning behavioral patterns.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:40,000 --> 00:20:44,000
|
| 1091 |
+
And I want to congratulate you as learning all behavioral patterns.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:44,000 --> 00:20:46,000
|
| 1095 |
+
Now, that's it.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:46,000 --> 00:20:49,000
|
| 1099 |
+
Have a great day and see you in the next lesson.
|
| 1100 |
+
|
39 - GoF Design Patterns of Software Architecture in OOP/007 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
39 - GoF Design Patterns of Software Architecture in OOP/external-links.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
002 Source-code-of-all-examples-from-the-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/creational
|
| 4 |
+
|
| 5 |
+
003 Source-code-of-all-examples-from-the-lesson
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/structural
|
| 7 |
+
|
| 8 |
+
004 Source-code-of-all-examples-from-the-lesson
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/structural
|
| 10 |
+
|
| 11 |
+
005 Source-code-of-all-examples-from-the-lesson
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
| 13 |
+
|
| 14 |
+
006 Source-code-of-all-examples-from-the-lesson
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
| 16 |
+
|
| 17 |
+
007 Source-code-of-all-examples-from-the-lesson
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/patterns/behavioral
|
40 - ===== Design Patterns Interview Questions =====/001 Part 1 OOP & Design Patterns Interview - Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 1 OOP & Design Patterns Interview - Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 1 OOP & Design Patterns Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT ARE DESIGN PATTERNS?</strong></p></li></ul><p><br></p><p>Design patterns are reusable solutions to common problems encountered in software development.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ELEMENTS IS THE DESIGN PATTERN COMPOSED OF?</strong></p></li></ul><p><br></p><p>In general, a template consists of four main elements:</p><ul><li><p>name. The exact name provides an opportunity to immediately understand the problem and determine the solution.</p></li><li><p>a goal. Scope within the framework of solving a specific problem;</p></li><li><p>solution. An abstract description of the design elements of the design problem and how to solve it using a generalized set of classes;</p></li><li><p>results.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF GOF PATTERNS DO YOU KNOW?</strong></p></li></ul><p><br></p><p>Creational patterns, structural patterns and behavior patterns as well as anti-patterns are distinguished.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>NAME THE CREATIONAL PATTERNS AND BRIEFLY DESCRIBE THEM</strong></p></li></ul><p><br></p><p>Creational patterns are intended to organize the process of creating objects.</p><p>The most common patterns are:</p><ul><li><p>Abstract Factory - provides an interface for creating related objects of families of classes without specifying their specific implementations (families of product objects);</p></li><li><p>Factory Method - defines an interface for creating objects from a hierarchical family of classes based on the transmitted data (subclass of object that is instantiated);</p></li><li><p>Builder - creates an object of a particular class in various ways (how a composite object gets created);</p></li><li><p>Singleton - guarantees the existence of only one or a finite number of instances of the class (the sole instance of a class);</p></li><li><p>Prototype - used when creating complex objects. Based on the prototype, objects are stored and recreated, for example, by copying.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>NAME THE BEHAVIORAL PATTERNS AND BRIEFLY DESCRIBE THEM.</strong></p></li></ul><p><br></p><p>GoF behavior patterns characterize the ways in which classes or objects interact with each other.</p><p>Behavioral patterns include:</p><ul><li><p>Chain of Responsibility - organizes a chain of recipient objects that do not know the capabilities of each other, independent of the sender object, and pass the request to each other (object that can fulfill a request);</p></li><li><p>Command - used to determine, by some attribute, an object of a particular class to which a request will be passed for processing (when and how a request is fulfilled);</p></li><li><p>Iterator (Iterator) - allows you to sequentially traverse all the elements of a collection or other composite object, without knowing the details of the internal data representation (how an aggregate's elements are accessed, traversed);</p></li><li><p>Mediator - allows you to reduce the number of connections between classes with a large number of them, highlighting one class that knows everything about the methods of other classes;</p></li><li><p>Memento - saves the current state of the object for further restoration;</p></li><li><p>Observer - allows for a one-to-many relationship between objects to track object changes;</p></li><li><p>State - allows an object to change its behavior by changing the internal state object.</p></li><li><p>Strategy - specifies a set of algorithms with the ability to select one of the classes to perform a specific task during object creation (an algorithm);</p></li><li><p>Template Method - creates a parent class that uses several methods, the implementation of which is assigned to derived classes (steps of an algorithm);</p></li><li><p>Visitor - Represents an operation in one or more related classes of some structure that is called by a method specific to each such class in another class (operations that can be applied to object(s) without changing their class(es));</p></li><li><p>Interpreter - for a certain way of presenting information defines the rules (grammar and interpretation of a language).</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>NAME THE STRUCTURAL PATTERNS AND BRIEFLY DESCRIBE THEM.</strong></p></li></ul><p><br></p><p>Structural GoF patterns are responsible for the composition of objects and classes, and not only for bringing together parts of an application, but also for separating them.</p><p>Structural patterns include:</p><ul><li><p>Adapter - is used when it is necessary to use classes together with unrelated interfaces. The behavior of the adaptable class is changed to the required one (interface to an object);</p></li><li><p>Bridge - separates the representation of the class and its implementation, allowing you to independently change both (implementation of an object);</p></li><li><p>Composite - groups objects into hierarchical tree structures and allows you to work with a single object in the same way as with a group of objects (structure and composition of an object);</p></li><li><p>Decorator - Represents a way to change the behavior of an object without creating subclasses. Allows you to use the behavior of one object in another (responsibilities of an object without subclassing);</p></li><li><p>Facade - creates a class with a common high-level interface to a certain number of interfaces in a subsystem (interface to a subsystem);</p></li><li><p>Flyweight - separates the properties of the class for optimal support for a large number of small objects (storage costs of objects);</p></li><li><p>Proxy - replaces a complex object with a simpler one and controls access to it</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT ANTI-PATTERNS DO YOU KNOW?</strong></p></li></ul><p><br></p><p>Some anti-patterns:</p><ul><li><p>Big ball of mud is a term for a system or simply a program that does not have even the slightest discernible architecture. Typically includes more than one anti-pattern. This affects systems developed by people with no training in software architecture.</p></li><li><p>Yo-Yo problem - arises when you need to understand the program, the inheritance hierarchy and the nesting of method calls are very long and complex. The programmer therefore needs to navigate between many different classes and methods in order to control the behavior of the program. The term comes from the name of the yo-yo toy.</p></li><li><p>Magic Button - occurs when the form processing code is concentrated in one place and, of course, is not structured in any way.</p></li><li><p>Magic Number - the presence in the code of repeated the same numbers or numbers, the explanation of the origin of which is missing.</p></li><li><p>Gas Factory - complex design for a simple task.</p></li><li><p>Analiys paralisys. In software development manifests itself through extremely long phases of project planning, collecting the necessary artifacts for this, software modeling and design, which do not make much sense to achieve the final goal.</p></li><li><p>Interface Bloat is a term used to describe interfaces that try to contain all possible operations on data.</p></li><li><p>Accidental complexity is a programming problem that could easily have been avoided. Occurs due to a misunderstanding of the problem or ineffective planning.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS OOAD?</strong></p></li></ul><p><br></p><p>OOAD, Object Oriented Analysis and Design - a discipline that describes the ways (options) of specifying (defining) objects and their interaction to solve a problem that is defined and described in the course of object-oriented analysis.</p><p><br></p><p>The main idea of object-oriented analysis and design is to consider the subject area and the logical solution of the problem from the point of view of objects (concepts and entities). In the process of object-oriented analysis, the main attention is paid to the definition and description of objects (or concepts) in terms of the subject area. In the process of object-oriented design, logical program objects are defined that will be implemented by means of an object-oriented programming language. These program objects include attributes and methods. And finally, in the process of designing (construction) or object-oriented programming (object-oriented programming), the implementation of the developed components and classes is provided.</p><p><br></p><ul><li><p><strong>WHAT IS OOD?</strong></p></li></ul><p><br></p><p>OOD, Object Oriented Design, is a design methodology that combines the process of object decomposition and techniques for representing the logical and physical, as well as static and dynamic models of the system being designed.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS OOA?</strong></p></li></ul><p><br></p><p>OOA, Object Oriented Analysis is a methodology in which system requirements are perceived in terms of classes and objects identified in the subject area, this is a design methodology that combines the process of object decomposition and techniques for representing logical and physical, as well as static and dynamic models of the designed system.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE DRY PRINCIPLES?</strong></p></li></ul><p><br></p><p>DRY, Don't repeat yourself - this principle is so important that it does not require repetition. This is a software development principle aimed at reducing the repetition of information of various kinds, especially in systems with many layers of abstraction. In simple words, DO NOT write repetitive code, use the principle of abstraction, generalizing simple things in one place.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS KISS?</strong></p></li></ul><p><br></p><p>KISS, Keep it short and simple or Keep it simple, stupid (keep things simple) is a design and programming principle that prohibits the use of more complex tools than necessary. The principle declares the simplicity of the system as the main goal and / or value.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS YAGNI?</strong></p></li></ul><p><br></p><p>YAGNI, You ain't gonna need it (You won't need it) is a software design process and principle in which the rejection of redundant functionality is declared as the main goal and / or value. The bottom line is to implement only the tasks defined and to abandon redundant functionality.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS YODA CONDITIONS?</strong></p></li></ul><p><br></p><p>Yoda conditions - A "safe" style of writing comparison expressions when programming in languages with C syntax, which consists in writing a constant member of the expression (constant or function call) to the left of the comparison operator (that is, 5 == a instead of habitual a == 5).</p><p><br></p><p>This style is intended to prevent the common mistake of these languages - the use of the assignment operator "=" instead of the comparison "==". The erroneous use of assignment turns Yoda's notation into an attempt to change a constant, causing a compile-time error, which eliminates the possibility of this type of error in the finished program, and also makes it easier to find and fix them in new code.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS CRC CARDS?</strong></p></li></ul><p><br></p><p>CRC cards, Class-responsibility-collaboration card (Class-Responsibility-Cooperation) is a brainstorming method for designing object-oriented software. As a rule, CRC-maps are used in those cases when classes and ways of their interactions are first defined in the software design process.</p><p><br></p><p>CRC maps focus the attention of the designer on the essence of the class and hide from him the details, the consideration of which at this stage would be counterproductive. CRCs also force the designer to refrain from assigning too many responsibilities to a class.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS SOLID?</strong></p></li></ul><p><br></p><p>SOLID, (single responsibility, open-closed, Liskov substitution, interface segregation, and dependency inversion) is an acronym for the first five principles, which stood for the five basic principles of object-oriented programming and design.</p><p><br></p><p>These principles, when applied together, are intended to increase the likelihood that a programmer will create a system that is easy to maintain and expand over time. The SOLID principles are guidelines that can be applied while working on software to remove "wrap around code" by instructing the programmer to refactor the source code until it is legible and extensible. This is part of an overall agile and adaptive development strategy.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS SINGLE RESPONSIBILITY PRINCIPLE?</strong></p></li></ul><p><br></p><p>Single responsibility principle - the principle of a single responsibility (one single responsibility should be assigned to each class). If one java class implements 2 sets of functions, their chaining creates a situation where changing one will break the combination.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS AN OPEN/CLOSED PRINCIPLE?</strong></p></li></ul><p><br></p><p>Open / closed principle - the principle of object-oriented programming, establishing the following position: "program entities (classes, modules, functions, etc.) must be open for extension, but closed for change"; this means that such entities can be allowed to change their behavior without changing their source code. How this can be implemented? Allow extension of the type. In this case we can override the behavior of the type without adjusting the source code of the original class. And by creating sufficient level of abstraction that wouldn’t force clients of your code to change the source code of original class.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS LISKOV SUBSTITUTION PRINCIPLE?</strong></p></li></ul><p><br></p><p>Liskov substitution principle - Barbara Liskov's substitution principle (functions that use a base type must be able to use subtypes of the base type without knowing it. Subclasses cannot replace the behavior of base classes. Subtypes must complement base types).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS INTERFACE SEGREGATION PRINCIPLE?</strong></p></li></ul><p><br></p><p>Interface segregation principle - the principle of interface separation (many specialized interfaces are better than one universal one). In other words, large, voluminous interfaces should be divided into small ones in such a way that clients of small interfaces know only about those methods that they need in their work. And so that when changing the interface methods, we wouldn’t change clients that don’t depend on the methods they don’t need and don’t use.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS DEPENDENCY INVERSION PRINCIPLE?</strong></p></li></ul><p><br></p><p>Dependency inversion principle - the principle of dependency inversion (dependencies within the system are built on the basis of abstractions. Top-level modules do not depend on lower-level modules. Abstractions should not depend on details. Details should depend on abstractions).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS GRASP?</strong></p></li></ul><p><br></p><p>GRASP, General Responsibility Assignment Software Patterns are design patterns used to solve general tasks of assigning responsibilities to classes and objects. Nine GRAPS patterns are known.</p><ul><li><p>Information expert</p></li><li><p>Creator</p></li><li><p>Controller</p></li><li><p>Indirection</p></li><li><p>Low coupling</p></li><li><p>High cohesion</p></li><li><p>Polymorphism</p></li><li><p>Protected variations</p></li><li><p>Pure fabrication</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>BRIEFLY DESCRIBE GRASP TEMPLATES.</strong></p></li></ul><p><br></p><p>GRASP identifies the following 9 template principles:</p><ul><li><p>Information Expert - An information expert describes the fundamental principles for assigning responsibilities to classes and objects. According to the description, an information expert (an object endowed with certain duties) is an object that has the maximum information necessary to perform the assigned duties.</p></li><li><p>Creator - the essence of the responsibility of such an object is that it creates other objects. The analogy with factories immediately suggests itself. That is correct. Factories also have a creation responsibility.</p></li><li><p>Controller - is responsible for processing input system events, delegating the responsibility for their processing to competent classes. In general, a controller implements one or more use cases. Using controllers allows you to separate logic from presentation, thereby increasing code reusability.</p></li><li><p>Low Coupling - If objects in an application are strongly coupled, then any change to them causes changes to all related objects. And this is inconvenient and generates bugs. That's why in all learning literature it is mentioned that it is necessary that the code be loosely coupled and depend only on abstractions.</p></li><li><p>High Cohesion - High cohesion is a software engineering concept that refers to how closely all the routines in a class, or all the code in a routine, support a central purpose. Classes that contain strongly related functionalities are described as having high cohesion.</p></li><li><p>Pure Fabrication is a class that doesn't represent any real domain object, but is specifically designed to increase cohesion, decoupling, or increase reuse. Pure Fabrication reflects the concept of services in the Domain Programming model.</p></li><li><p>Indirection - the redirection pattern implements low coupling between classes by assigning responsibilities for their interaction to an additional object - an intermediary.</p></li><li><p>Protected Variations - Protects elements from being modified by other elements (objects or subsystems) by making the interaction a fixed interface. All interaction between elements must occur through it. The behavior can only be changed by creating a different implementation of the interface.</p></li><li><p>Polymorphism - allows you to handle alternative behaviors based on type and replace plug-in system components. Responsibilities are allocated to different behaviors using polymorphic operations for that class. All alternative implementations are cast to a common interface.</p></li></ul><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
And our team in this lesson, we're going to go internationalization and localization in Java.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:17,000
|
| 7 |
+
We're going to study this lesson from this stand in on the challenge that you are one of us.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:24,000
|
| 11 |
+
With the help of internationalization and localization, once we understand the challenge will proceed
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:24,000 --> 00:00:31,000
|
| 15 |
+
as none of these two concepts, I will explain the difference between these two charms.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:32,000 --> 00:00:34,000
|
| 19 |
+
Also, today, we will have a lot of practical activities.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:35,000 --> 00:00:43,000
|
| 23 |
+
We will learn how to work with local objects on real examples using local object format, numbers,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:43,000 --> 00:00:47,000
|
| 27 |
+
currencies and dates, and examples of the lessons learned.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:47,000 --> 00:00:49,000
|
| 31 |
+
How to work with resource bundles.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:49,000 --> 00:00:55,000
|
| 35 |
+
I'll show you how to work with properties based in Java based resource bundles on real examples.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:55,000 --> 00:01:00,000
|
| 39 |
+
This is going to be very productive lesson as Gary started.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:01,000 --> 00:01:08,000
|
| 43 |
+
Let's understand the problems that we tried to address here and why we need a rationalization and localization
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:09,000 --> 00:01:17,000
|
| 47 |
+
and why we should care about it nowadays, in most cases, developers work on the applications that
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:17,000 --> 00:01:24,000
|
| 51 |
+
are supposed to be scaled across multiple regions, at least very often apps supposed to be available
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:24,000 --> 00:01:25,000
|
| 55 |
+
in multiple countries.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:26,000 --> 00:01:31,000
|
| 59 |
+
This is widespread, non-functional requirements that software engineers should implement.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:32,000 --> 00:01:39,000
|
| 63 |
+
Have an application available across different countries means that we need to handle various regional
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:39,000 --> 00:01:46,000
|
| 67 |
+
specific data, considering our application supposed to serve people from different parts of the world.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:46,000 --> 00:01:52,000
|
| 71 |
+
We should take into our towns cultural and political specifics, new ones and data representation.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:52,000 --> 00:01:55,000
|
| 75 |
+
For example, numbers, dates.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:55,000 --> 00:01:56,000
|
| 79 |
+
Currency stacks.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:58,000 --> 00:02:01,000
|
| 83 |
+
Now, let's understand what internationalization is.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:02:01,000 --> 00:02:09,000
|
| 87 |
+
The first thing I'd like to explain is abbreviations that is used instead of a long word internationalization.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:10,000 --> 00:02:14,000
|
| 91 |
+
As you see, usually it is named as IE 18.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:14,000 --> 00:02:23,000
|
| 95 |
+
And then number 18 here is due to 18 letters between I and and that's why all it is first, that they
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:23,000 --> 00:02:27,000
|
| 99 |
+
use this abbreviation instead of writing a whole verb.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:28,000 --> 00:02:31,000
|
| 103 |
+
So what is internationalization?
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:31,000 --> 00:02:39,000
|
| 107 |
+
First of all, this is a process process of what process of making software available to be used for
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:39,000 --> 00:02:46,000
|
| 111 |
+
different regions and by removing any handwriting and building application architecture is the way it
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:46,000 --> 00:02:49,000
|
| 115 |
+
potentially can support multiple different regions.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:50,000 --> 00:02:59,000
|
| 119 |
+
Internationalization ensures your software is localized and is typically done by software developers
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:59,000 --> 00:03:00,000
|
| 123 |
+
and engineers.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:03:00,000 --> 00:03:07,000
|
| 127 |
+
Even if your original software, architecture and marketing campaign is oriented, funds are large on
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:03:07,000 --> 00:03:08,000
|
| 131 |
+
the one market Romney.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:09,000 --> 00:03:16,000
|
| 135 |
+
Let's see some English speaking market internationalization allows it to ensure it could support all
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:16,000 --> 00:03:18,000
|
| 139 |
+
the languages and cultures.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:19,000 --> 00:03:27,000
|
| 143 |
+
If you were to expand to additional markets in the future, so instead of high scoring individual language
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:27,000 --> 00:03:34,000
|
| 147 |
+
inside application internationalization helps you to prepare your code base for using different configurations
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:35,000 --> 00:03:41,000
|
| 151 |
+
and translations based on the local news and internationalization.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:41,000 --> 00:03:47,000
|
| 155 |
+
We also replace caught with some placeholders, which will be used to retrieve localized version of
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:47,000 --> 00:03:50,000
|
| 159 |
+
the content from the provided configuration files.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:51,000 --> 00:03:55,000
|
| 163 |
+
To help you understand how this works, let's imagine example.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:56,000 --> 00:04:01,000
|
| 167 |
+
Together with all students, we implement our online shop during learning.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:04:01,000 --> 00:04:08,000
|
| 171 |
+
Our job, of course, and on the welcome screen Zoom option to log in in the English version of the
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:08,000 --> 00:04:09,000
|
| 175 |
+
app.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:09,000 --> 00:04:11,000
|
| 179 |
+
We should use log in tax here.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:11,000 --> 00:04:19,000
|
| 183 |
+
But in Russian version of the app, we have to use wiki tax inside our code.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:19,000 --> 00:04:24,000
|
| 187 |
+
We need to identify place where our place code of the bottom tax will be used.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:25,000 --> 00:04:34,000
|
| 191 |
+
So during the coding of the app, we may use logging tax gone placeholder later inside our localized
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:34,000 --> 00:04:35,000
|
| 195 |
+
configuration file.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:36,000 --> 00:04:42,000
|
| 199 |
+
We'll use the same key to define content for that key for different versions.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:42,000 --> 00:04:50,000
|
| 203 |
+
Similar approach in sudsy code will be applied to date time for US currency and all the components.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:51,000 --> 00:04:55,000
|
| 207 |
+
Instead of coding is the software for each specific language.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:55,000 --> 00:05:00,000
|
| 211 |
+
Internationalization process replaces that code in this case.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:00,000 --> 00:05:08,000
|
| 215 |
+
This not only makes code base easier for localization, but it also neutralized the code and adopts
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:08,000 --> 00:05:09,000
|
| 219 |
+
it for various languages.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:10,000 --> 00:05:11,000
|
| 223 |
+
You may introduce in the future.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:12,000 --> 00:05:21,000
|
| 227 |
+
Now, it's time for us to learn what localization is, localization is a process of adapting your internationalized
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:21,000 --> 00:05:29,000
|
| 231 |
+
software to needs a language, cultural and other requirements of a specific target market otherwise
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:29,000 --> 00:05:34,000
|
| 235 |
+
known as locale by engine resources and translating content.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:35,000 --> 00:05:41,000
|
| 239 |
+
We also often use abbreviation for localization like we do for internationalization.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:41,000 --> 00:05:49,000
|
| 243 |
+
We use our Dan and app because between AL and zero, rather than characters.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:49,000 --> 00:05:57,000
|
| 247 |
+
In simple words, localization is performed by translation of content on user facing elements and components
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:57,000 --> 00:05:58,000
|
| 251 |
+
of your application.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:59,000 --> 00:06:04,000
|
| 255 |
+
But localization goes beyond translations and text or presentations.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:06:05,000 --> 00:06:13,000
|
| 259 |
+
When we talk about localization or adaptation of all visual content, the specific local zoning includes
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:06:13,000 --> 00:06:20,000
|
| 263 |
+
but not limited to numbers, currencies, dates, images, et cetera.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:21,000 --> 00:06:25,000
|
| 267 |
+
Let's review a few examples that will be different for different regions.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:25,000 --> 00:06:28,000
|
| 271 |
+
To help you understand what localization is.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:29,000 --> 00:06:30,000
|
| 275 |
+
For example, numbers.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:30,000 --> 00:06:36,000
|
| 279 |
+
If you are a student of my Java course, then you already know that during the course, we implement
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:36,000 --> 00:06:43,000
|
| 283 |
+
online shop in online shopping display no surprises and for different regions, use different parts
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:43,000 --> 00:06:46,000
|
| 287 |
+
and established to separate fractional part.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:47,000 --> 00:06:53,000
|
| 291 |
+
For instance, in the United States, you have separate spouses was comma and sans was done.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:54,000 --> 00:07:00,000
|
| 295 |
+
But in Russia it would separate thousands with space or fractional portals because this comma.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:07:00,000 --> 00:07:07,000
|
| 299 |
+
But in Germany, will you all for spousal separation and comma to separate fractional part?
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:08,000 --> 00:07:10,000
|
| 303 |
+
We talk about manual representation.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:10,000 --> 00:07:19,000
|
| 307 |
+
Currency symbols supposed to be different to the same amount need to represent US dollar sign Russian
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:19,000 --> 00:07:23,000
|
| 311 |
+
rubble using Indian rupee or British pound.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:24,000 --> 00:07:31,000
|
| 315 |
+
An important fact to know is that even if countries have the same currency in currencies single like
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:31,000 --> 00:07:36,000
|
| 319 |
+
France and Italy, the position of their currencies single could be different.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:37,000 --> 00:07:45,000
|
| 323 |
+
Date and time representation also arise in the U.S. for months in my job, of course, insurance was
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:45,000 --> 00:07:48,000
|
| 327 |
+
unique on time and you know how painful.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:48,000 --> 00:07:55,000
|
| 331 |
+
Sometimes it may be managing different time zones, but also there are different regions specific in
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:55,000 --> 00:08:02,000
|
| 335 |
+
different time zones to represent the time to optimize the process of localization.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:08:02,000 --> 00:08:10,000
|
| 339 |
+
Engineers can create different source files, so-called resource bundles for each locale.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:08:10,000 --> 00:08:16,000
|
| 343 |
+
This resource bundles will store all the tax outside of zip code of the product.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:08:16,000 --> 00:08:24,000
|
| 347 |
+
This allows us to build our application in a way when we use these sources, those and apply different
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:08:24,000 --> 00:08:26,000
|
| 351 |
+
ones based on the concrete locale.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:27,000 --> 00:08:35,000
|
| 355 |
+
In this way, we don't make any harm to our code, and not constantly changing it from the technical
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:35,000 --> 00:08:41,000
|
| 359 |
+
side is of great importance is the process of localization belongs to local time.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:42,000 --> 00:08:47,000
|
| 363 |
+
Before jumping to practical example, there will be examples of using local.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:47,000 --> 00:08:53,000
|
| 367 |
+
Let's review a little bit of series about this class of a local class java.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:54,000 --> 00:09:01,000
|
| 371 |
+
You too vocal is used to represent a geographical, political or cultural region to localize it, even
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:09:01,000 --> 00:09:03,000
|
| 375 |
+
tax number or date.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:09:04,000 --> 00:09:11,000
|
| 379 |
+
A local object may just contain the country language and also a variant of language.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:09:11,000 --> 00:09:18,000
|
| 383 |
+
For instance, a dialect spoken in a certain region of a country or spoken in a different country is
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:09:18,000 --> 00:09:21,000
|
| 387 |
+
in the country from which the language originates.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:09:21,000 --> 00:09:28,000
|
| 391 |
+
The concept of Java Local is implemented by the Java due to local class that defines local.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:09:28,000 --> 00:09:36,000
|
| 395 |
+
For the application, you would use the local object, which is only and identify the local class,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:36,000 --> 00:09:41,000
|
| 399 |
+
can't do any internationalization or localization by itself.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:42,000 --> 00:09:49,000
|
| 403 |
+
Real localization is done by local sensitive classes or objects that you create for local sensitive
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:49,000 --> 00:09:56,000
|
| 407 |
+
classes customized themselves as to how to format and represent data to the user.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:57,000 --> 00:10:03,000
|
| 411 |
+
This class is used as a local object to understand which local is being used in the application.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:10:04,000 --> 00:10:14,000
|
| 415 |
+
So we create local and we will set local in our application to make other local sensitive objects behave
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:10:14,000 --> 00:10:18,000
|
| 419 |
+
differently when needed and also to use proper resource bundles.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:10:19,000 --> 00:10:24,000
|
| 423 |
+
A local instance contains the following supports language.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:10:25,000 --> 00:10:33,000
|
| 427 |
+
This can be an ISO 639 all city office record or registered language subtype.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:10:33,000 --> 00:10:40,000
|
| 431 |
+
In case a language has rules at two and three, cats or language could use that tax character cut,
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:10:41,000 --> 00:10:48,000
|
| 435 |
+
a full list of language codes can be found in the I Am a Language Setback registry.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:10:48,000 --> 00:10:51,000
|
| 439 |
+
What is our elite AI?
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:10:51,000 --> 00:10:56,000
|
| 443 |
+
And they stands for the interior, the signs members of sovereignty.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:10:56,000 --> 00:11:04,000
|
| 447 |
+
It is a standards organisation that oversees global IP address allocation, autonomous system allocation,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:11:05,000 --> 00:11:12,000
|
| 451 |
+
root zone management e.g. domain name system that is DNS, many other types and also easier.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:11:12,000 --> 00:11:15,000
|
| 455 |
+
A The length related symbols and internet numbers.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:11:15,000 --> 00:11:18,000
|
| 459 |
+
Language codes at case and sensitive.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:11:18,000 --> 00:11:23,000
|
| 463 |
+
But the local class always use lower case versions of the language codes.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:11:24,000 --> 00:11:31,000
|
| 467 |
+
Scripts must be a valid ISO fifty nine hundred twenty four Alpha four code.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:11:32,000 --> 00:11:36,000
|
| 471 |
+
This script represents a written form of the language.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:11:36,000 --> 00:11:39,000
|
| 475 |
+
Some languages can be written using different scripts.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:11:40,000 --> 00:11:41,000
|
| 479 |
+
Different alphabets.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:11:42,000 --> 00:11:50,000
|
| 483 |
+
Country region, the country code is still cancer code follows an ISO setting one six two six standard
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:11:51,000 --> 00:11:55,000
|
| 487 |
+
oral U.N. and forty nine numeric area code.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:11:55,000 --> 00:12:02,000
|
| 491 |
+
A full list of four country and region codes can be found in the AI language stack registry.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:12:03,000 --> 00:12:12,000
|
| 495 |
+
Where it's a case sensitive value will set a value specifying a variation of the local variance for
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:12:12,000 --> 00:12:18,000
|
| 499 |
+
scraps of area of a language for falls in Mississippi for a certain standard.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:12:19,000 --> 00:12:20,000
|
| 503 |
+
Extensions.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:12:21,000 --> 00:12:27,000
|
| 507 |
+
The extension cord signals extensions to the local, in addition to the language and region, for instance,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:12:27,000 --> 00:12:30,000
|
| 511 |
+
what calendar to use when displaying dates?
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:12:30,000 --> 00:12:31,000
|
| 515 |
+
Wiggle room.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:12:32,000 --> 00:12:34,000
|
| 519 |
+
Japanese, et cetera.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:12:35,000 --> 00:12:41,000
|
| 523 |
+
Now, let's make sure that the difference between internationalization and localization is clear for
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:12:41,000 --> 00:12:47,000
|
| 527 |
+
us, despite the fact that both of these storms are used to achieve the same goal.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:12:47,000 --> 00:12:50,000
|
| 531 |
+
Several different differences between these channels.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:12:51,000 --> 00:12:52,000
|
| 535 |
+
So what is the difference?
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:12:53,000 --> 00:13:00,000
|
| 539 |
+
Internationalization is a process of designing and developing your software or mobile application code
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:13:01,000 --> 00:13:07,000
|
| 543 |
+
so it can be adopted and localized to different cultures, regions and languages.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:13:08,000 --> 00:13:16,000
|
| 547 |
+
Localization is the other station of your software or mobile application product in the language, culture
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:13:16,000 --> 00:13:18,000
|
| 551 |
+
and also requirements of each local.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:13:19,000 --> 00:13:26,000
|
| 555 |
+
Things a difference Already, internationalization helps you build your software or mobile application
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:13:26,000 --> 00:13:30,000
|
| 559 |
+
product in these future markets and languages in mind.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:13:31,000 --> 00:13:39,000
|
| 563 |
+
It is a process of neutralizing support, quantum and design so that down the road it will be easier
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:13:39,000 --> 00:13:44,000
|
| 567 |
+
to adapt your product to additional cultures without having to completely re-engineer.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:13:45,000 --> 00:13:49,000
|
| 571 |
+
Localization typically follows internationalization.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:13:49,000 --> 00:13:58,000
|
| 575 |
+
But beyond adapting yourself to a specific region is an localization process can also highlight any
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:58,000 --> 00:14:05,000
|
| 579 |
+
words, phrases or user interface elements that have incorrectly been internationalized.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:14:06,000 --> 00:14:10,000
|
| 583 |
+
How is it now the difference between these two camps is clear?
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:14:11,000 --> 00:14:19,000
|
| 587 |
+
Now, let's have a demo of local and examples of modern considering internationalization and four rules.
|
| 588 |
+
|
41 - I18N & L10N/002 Source-code-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/l18ni10n
|
41 - I18N & L10N/002 [Part 2] Localization and Internationalization_en.srt
ADDED
|
@@ -0,0 +1,872 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:13,000
|
| 3 |
+
Let's start our demo from local clubs, let us we are going to use logo in different scenarios in the
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:13,000 --> 00:00:13,000
|
| 7 |
+
lesson.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:18,000
|
| 11 |
+
That's why I believe it will be logical to start from this first review first.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:22,000
|
| 15 |
+
That's known how we can create local objects.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:23,000 --> 00:00:27,000
|
| 19 |
+
First of all, I want to mention that there are several constants in the local class.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:33,000
|
| 23 |
+
You can refer to any of these concerns instead of creating new local objects from scratch.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:33,000 --> 00:00:40,000
|
| 27 |
+
So using constants will be the first way to obtain the references in local object you.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:40,000 --> 00:00:44,000
|
| 31 |
+
Second way to instantiate local objects is a real constructor.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:44,000 --> 00:00:48,000
|
| 35 |
+
I have separate class kids at the school local demo.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:48,000 --> 00:00:51,000
|
| 39 |
+
I put all examples related to the local insets class.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:52,000 --> 00:01:00,000
|
| 43 |
+
You can create local was a help over a new keyword, and Collins, a constructor constructor is overloaded
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:00,000 --> 00:01:03,000
|
| 47 |
+
and you may use any variation of constructor you like the most.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:04,000 --> 00:01:10,000
|
| 51 |
+
For example, zero constructors where you can pass on the language or you can pass language code and
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:10,000 --> 00:01:14,000
|
| 55 |
+
country quote, or you can pass language, country and variant codes.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:15,000 --> 00:01:19,000
|
| 59 |
+
And here in demo file, I create four different locales.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:20,000 --> 00:01:24,000
|
| 63 |
+
The first one is for Hindi language and in their country.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:24,000 --> 00:01:32,000
|
| 67 |
+
The second one is for English language and India country, because sometimes we may want to use English
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:32,000 --> 00:01:33,000
|
| 71 |
+
language for India country.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:34,000 --> 00:01:43,000
|
| 75 |
+
Based on this local object, we will select a service bundle that fits in most our local language country
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:43,000 --> 00:01:46,000
|
| 79 |
+
and very similar cases was another.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:46,000 --> 00:01:50,000
|
| 83 |
+
Local people in Ukraine speak some different languages.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:50,000 --> 00:01:57,000
|
| 87 |
+
You can set Russian language for Ukraine country and prepare a source, Bongo's, for this version of
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:57,000 --> 00:01:58,000
|
| 91 |
+
local.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:58,000 --> 00:02:03,000
|
| 95 |
+
And you can also create local for Ukrainian language for Ukraine country.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:04,000 --> 00:02:11,000
|
| 99 |
+
After having the local object, you can pass it as massive argument to the local sensitive objects like
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:11,000 --> 00:02:13,000
|
| 103 |
+
we discussed using slides.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:13,000 --> 00:02:21,000
|
| 107 |
+
Overview The language parameter should be a two or three letter ISO language code from ISO 669 standard.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:22,000 --> 00:02:26,000
|
| 111 |
+
You can also use the language stack of up to eight characters.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:27,000 --> 00:02:34,000
|
| 115 |
+
The country should be two character ISO country code from ISO setting one six two six standard.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:34,000 --> 00:02:40,000
|
| 119 |
+
Alternatively, you +49 character area code can be used.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:41,000 --> 00:02:46,000
|
| 123 |
+
Zverev should be an invalid VCP 47 variants of the language.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:47,000 --> 00:02:55,000
|
| 127 |
+
This sort of way of creating local object is using of local builder, you just instantiate objects of
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:55,000 --> 00:02:56,000
|
| 131 |
+
nested class.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:56,000 --> 00:03:03,000
|
| 135 |
+
Local builder and after that, you set your smart assets to sell the properties once configuration is
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:03,000 --> 00:03:03,000
|
| 139 |
+
done.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:04,000 --> 00:03:10,000
|
| 143 |
+
You can call build muscle that will return as a reference to the local object with the local builder.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:10,000 --> 00:03:13,000
|
| 147 |
+
It is easy to sense create an extension if you wish.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:14,000 --> 00:03:21,000
|
| 151 |
+
And the force option to create local object is static mass at the full language stack of local cloth.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:22,000 --> 00:03:28,000
|
| 155 |
+
You can call it and cross language studies that may consist of language and country codes.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:29,000 --> 00:03:33,000
|
| 159 |
+
There are different ways how you can check all available calls.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:33,000 --> 00:03:39,000
|
| 163 |
+
Just in case you want to check whether your local is supported or you forgot the codes of language or
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:39,000 --> 00:03:43,000
|
| 167 |
+
country and you don't want to check it in the internet.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:44,000 --> 00:03:47,000
|
| 171 |
+
You can check it in another way directly in your program.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:48,000 --> 00:03:55,000
|
| 175 |
+
You can call get a lot of the locals is a local plus or a number for them up or on the date form of
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:55,000 --> 00:03:56,000
|
| 179 |
+
class.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:56,000 --> 00:04:00,000
|
| 183 |
+
You will receive an array of all available and supported locales.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:01,000 --> 00:04:09,000
|
| 187 |
+
And sign you up, you can easily identified the local, the local is notified was environment where
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:09,000 --> 00:04:10,000
|
| 191 |
+
G.M. is running.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:10,000 --> 00:04:18,000
|
| 195 |
+
For example, I have Russian local counties sat in my Windows operating system and I can easily identify
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:18,000 --> 00:04:20,000
|
| 199 |
+
these by call and get the local message.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:21,000 --> 00:04:27,000
|
| 203 |
+
And in case I want to set new shop local, I can use said default massive.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:28,000 --> 00:04:35,000
|
| 207 |
+
For example, during the mobile development and Android system, one user wants to change language inside
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:35,000 --> 00:04:36,000
|
| 211 |
+
that application.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:37,000 --> 00:04:41,000
|
| 215 |
+
What you do basically is changing the default local to the one selected by user.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:42,000 --> 00:04:51,000
|
| 219 |
+
I believe now, you know enough about local let us know how we can use it in single localisation examples.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:51,000 --> 00:04:53,000
|
| 223 |
+
Let's open localization demo file.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:54,000 --> 00:04:58,000
|
| 227 |
+
Let me read this example and walk you as soon as it comes out.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:59,000 --> 00:05:06,000
|
| 231 |
+
Imagine that we have some random double value unless your represents double value, considering local
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:06,000 --> 00:05:08,000
|
| 235 |
+
specifics of different regions.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:09,000 --> 00:05:10,000
|
| 239 |
+
I agree.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:10,000 --> 00:05:17,000
|
| 243 |
+
No format of my column get instance massive and boss us call.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:18,000 --> 00:05:21,000
|
| 247 |
+
After that, I call form Massad of No.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:21,000 --> 00:05:28,000
|
| 251 |
+
Four Object, and plus our random number will use that and I do the same operation with Russian and
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:28,000 --> 00:05:31,000
|
| 255 |
+
German local in console.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:31,000 --> 00:05:35,000
|
| 259 |
+
You can see single examples that we discussed during the slide show.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:35,000 --> 00:05:41,000
|
| 263 |
+
You can see how thousands and functional cards are separated in different local.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:42,000 --> 00:05:47,000
|
| 267 |
+
Sometimes it is just a space, sometimes it this coma, and sometimes it a point.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:48,000 --> 00:05:48,000
|
| 271 |
+
Is it clear?
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:49,000 --> 00:05:58,000
|
| 275 |
+
Now on no of glass, I call static mass to get currency influence and bust different local and call
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:58,000 --> 00:05:59,000
|
| 279 |
+
formats massive.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:00,000 --> 00:06:04,000
|
| 283 |
+
You can see that currency sign is at its jewels of four mind.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:05,000 --> 00:06:09,000
|
| 287 |
+
You can see the dollar euro rebel rupee.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:09,000 --> 00:06:16,000
|
| 291 |
+
Both sides are added to our random double value, depending on the locals that we use for money.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:17,000 --> 00:06:19,000
|
| 295 |
+
And you can see that automatically.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:19,000 --> 00:06:26,000
|
| 299 |
+
Currencies sign is positioned either before or after numeric value based on the specifics of a region.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:27,000 --> 00:06:35,000
|
| 303 |
+
Also, be aware that you might see in question marks instead of currency signs in case you can't see
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:35,000 --> 00:06:36,000
|
| 307 |
+
currency signs.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:37,000 --> 00:06:41,000
|
| 311 |
+
That means in court in your I.D. is set correctly.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:41,000 --> 00:06:51,000
|
| 315 |
+
The changing coding click window preferences darken code in here and sign here workspace section in
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:51,000 --> 00:06:54,000
|
| 319 |
+
the text file and according to Act UTF eight.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:55,000 --> 00:06:55,000
|
| 323 |
+
That's it.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:56,000 --> 00:07:01,000
|
| 327 |
+
After applying this configuration, you will be able to see and see signs.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:02,000 --> 00:07:07,000
|
| 331 |
+
Right, wind, guys, you can find the reference to all the court examples in attachments to the lesson
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:08,000 --> 00:07:15,000
|
| 335 |
+
also encourage you to run these examples on your computer and play around with different masses and
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:15,000 --> 00:07:15,000
|
| 339 |
+
locales.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:16,000 --> 00:07:19,000
|
| 343 |
+
This will help you to understand the topic better.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:20,000 --> 00:07:27,000
|
| 347 |
+
The last example here is the example of the four, Martin, I agree, isn't the time object.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:28,000 --> 00:07:34,000
|
| 351 |
+
And after that was the help of date time for Martha by former date was different locales.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:35,000 --> 00:07:40,000
|
| 355 |
+
If you're a student of my job, of course, please refer to the lesson about date and time.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:40,000 --> 00:07:47,000
|
| 359 |
+
Where we reviewed different ways to work was date and time, including classes from Java Time Package.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:47,000 --> 00:07:51,000
|
| 363 |
+
There are different classes that work was local to form of date.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:52,000 --> 00:07:58,000
|
| 367 |
+
I just showed one example, but I'm sure that you understood how it works.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:58,000 --> 00:08:06,000
|
| 371 |
+
And the last, but not least for this lesson resource bundles or resource bundles basically localized
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:06,000 --> 00:08:07,000
|
| 375 |
+
resources.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:08,000 --> 00:08:11,000
|
| 379 |
+
We are going to review different forms of resource bundles.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:11,000 --> 00:08:15,000
|
| 383 |
+
Let's start from the properties based resource bundles.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:15,000 --> 00:08:19,000
|
| 387 |
+
First of all, I made the resource folder, my source folder.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:20,000 --> 00:08:21,000
|
| 391 |
+
How I did that.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:22,000 --> 00:08:29,000
|
| 395 |
+
You can mouse right click on a resource folder built by us and select Use as a source folder.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:30,000 --> 00:08:32,000
|
| 399 |
+
I already have resources for them.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:32,000 --> 00:08:34,000
|
| 403 |
+
What a source folder.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:34,000 --> 00:08:43,000
|
| 407 |
+
That's why I show these examples on the folder, but I believe this is clear why this is needed because
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:43,000 --> 00:08:51,000
|
| 411 |
+
resource bundles should be located in the class box, but it is not a good idea to put properties.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:51,000 --> 00:08:54,000
|
| 415 |
+
Files in the same folder was the source code.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:55,000 --> 00:09:01,000
|
| 419 |
+
That's why it is a rule of thumb to have some folders dedicated for storing resources.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:02,000 --> 00:09:05,000
|
| 423 |
+
Let's review what resource bundles we have.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:06,000 --> 00:09:10,000
|
| 427 |
+
We have my labels resource bundle here and different versions of it.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:11,000 --> 00:09:13,000
|
| 431 |
+
We have default version of my labels.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:14,000 --> 00:09:17,000
|
| 435 |
+
Also, we have bundle for and yes and four.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:19,000 --> 00:09:21,000
|
| 439 |
+
This files have properties extension.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:22,000 --> 00:09:26,000
|
| 443 |
+
Let's open them one by one in the Default Resource Bundle.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:26,000 --> 00:09:34,000
|
| 447 |
+
You can see a set of key value pass these keys I used inside the code of application and the various
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:34,000 --> 00:09:40,000
|
| 451 |
+
a substituted instead of placeholders in the program execution, depending on the local set.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:40,000 --> 00:09:47,000
|
| 455 |
+
Inside the app is the default property, so you can see that the welcome message is sound like welcome
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:47,000 --> 00:09:51,000
|
| 459 |
+
sir, and the log in button text is log in.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:51,000 --> 00:09:58,000
|
| 463 |
+
We can write comments in property files like this, starting with no sign or exclamation mark.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:59,000 --> 00:10:02,000
|
| 467 |
+
So most of these options are considered to be invalid.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:02,000 --> 00:10:03,000
|
| 471 |
+
Common syntax.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:04,000 --> 00:10:07,000
|
| 475 |
+
Also, we can read key value parents in different ways.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:07,000 --> 00:10:13,000
|
| 479 |
+
We can easily use equals sign or column, all like in any US motion.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:13,000 --> 00:10:17,000
|
| 483 |
+
I can simply use space between key and value.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:18,000 --> 00:10:22,000
|
| 487 |
+
In the end, you ask Marshall, welcome message is just welcome.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:23,000 --> 00:10:25,000
|
| 491 |
+
And look at the bottom tax is signing.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:26,000 --> 00:10:32,000
|
| 495 |
+
In the rural version, we have welcome message, but we don't have a slogan tax mutton.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:33,000 --> 00:10:34,000
|
| 499 |
+
What does this mean?
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:34,000 --> 00:10:36,000
|
| 503 |
+
This means of logging money.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:36,000 --> 00:10:40,000
|
| 507 |
+
Text will be taken from the default resource bundle.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:41,000 --> 00:10:48,000
|
| 511 |
+
And what these Unicode characters mean, this thing is was among those uploaded into Gmail.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:48,000 --> 00:10:51,000
|
| 515 |
+
We abide streams in Java version eight and below.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:52,000 --> 00:10:58,000
|
| 519 |
+
If you don't remember what barred streams are least referred to, the lessons about input output streams
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:59,000 --> 00:11:06,000
|
| 523 |
+
ensure wide streams, read data, provide and torrent of streams that appear to box.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:06,000 --> 00:11:13,000
|
| 527 |
+
That means that it is impossible to describe all your characters in one bite.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:13,000 --> 00:11:21,000
|
| 531 |
+
That's why there's a workaround or just file so automatic conversion of characters not supported by
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:21,000 --> 00:11:22,000
|
| 535 |
+
asking.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:22,000 --> 00:11:30,000
|
| 539 |
+
According to Unicode numbers, for example, all Russian leaders here are using Unicode numbers, and
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:30,000 --> 00:11:31,000
|
| 543 |
+
this is done automatically.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:32,000 --> 00:11:38,000
|
| 547 |
+
So in case I would write something with Russian letters, my I.D. will convert it in Unicode numbers.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:39,000 --> 00:11:45,000
|
| 551 |
+
Fortunately, this inconvenience exists no longer in Java nine and upper versions.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:46,000 --> 00:11:53,000
|
| 555 |
+
JVM reads progressive files in UTF eight encoding, and there is no problem in using non Latin characters.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:54,000 --> 00:12:02,000
|
| 559 |
+
But still considering the fact that even after the release of Java version 16, Java eight is the most
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:02,000 --> 00:12:07,000
|
| 563 |
+
popular Java version, I was recommended to not ignore this limitation.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:08,000 --> 00:12:13,000
|
| 567 |
+
OK, now we have four service bundles and key value pairs described here.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:14,000 --> 00:12:18,000
|
| 571 |
+
Let's take a look at how this is implemented on the code level.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:19,000 --> 00:12:21,000
|
| 575 |
+
I open the reserve's bundle demo file.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:22,000 --> 00:12:25,000
|
| 579 |
+
I create object of Resource Bundle how I can do that.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:26,000 --> 00:12:32,000
|
| 583 |
+
I call Get Bundle Massad Officers Bundle class and pass name of my bundle.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:33,000 --> 00:12:41,000
|
| 587 |
+
Pay attention that each man has base name all bundles for those three naming convention, their base
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:41,000 --> 00:12:43,000
|
| 591 |
+
name and different versions.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:44,000 --> 00:12:50,000
|
| 595 |
+
You can specify language, country and variant, and separate all elements of the resource bundle name.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:50,000 --> 00:12:58,000
|
| 599 |
+
We are underscores when you create Object Officers bundle in Java, you use only base name and you let
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:58,000 --> 00:13:03,000
|
| 603 |
+
Java decide which resource bundles to use based on the local set.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:04,000 --> 00:13:07,000
|
| 607 |
+
Let's make sure the default locale is through.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:08,000 --> 00:13:16,000
|
| 611 |
+
The next line of code in our example is extracting value from resource bundle by its key, let's say,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:16,000 --> 00:13:17,000
|
| 615 |
+
welcome in Russian.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:18,000 --> 00:13:22,000
|
| 619 |
+
I will run the program to explore console outputs together with you.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:23,000 --> 00:13:28,000
|
| 623 |
+
I use guest drink massive on my research bundle object and boss key.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:28,000 --> 00:13:30,000
|
| 627 |
+
This is exactly what you should need.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:30,000 --> 00:13:33,000
|
| 631 |
+
You're working on internationalization in your app.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:34,000 --> 00:13:40,000
|
| 635 |
+
This approach will allow you to run your app on the market by simply adding your resource bundle.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:40,000 --> 00:13:41,000
|
| 639 |
+
That said.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:42,000 --> 00:13:50,000
|
| 643 |
+
But what will happen if I would try to extract value for logging bottom tax that is absent in the resource
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:50,000 --> 00:13:51,000
|
| 647 |
+
bundle?
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:51,000 --> 00:13:54,000
|
| 651 |
+
Value from the falls, my look will be taken.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:55,000 --> 00:13:56,000
|
| 655 |
+
Let me show you this.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:57,000 --> 00:14:05,000
|
| 659 |
+
And as you can see in so even despite we have Russian local set, we get taxed in English because the
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:05,000 --> 00:14:12,000
|
| 663 |
+
value for this key is just absent in Russian version of the source bundle and default version is taken.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:13,000 --> 00:14:14,000
|
| 667 |
+
Can you understand this?
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:15,000 --> 00:14:22,000
|
| 671 |
+
And logically, after I changed local to and yes and print its values for these two kids using the same
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:22,000 --> 00:14:27,000
|
| 675 |
+
place holders, I get values from another version of my research bundle.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:28,000 --> 00:14:31,000
|
| 679 |
+
You can also see examples with the for local.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:32,000 --> 00:14:39,000
|
| 683 |
+
I believe you already understood how properties based resource bundles were retention that I applaud
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:39,000 --> 00:14:42,000
|
| 687 |
+
the resource bundle after I change in local.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:43,000 --> 00:14:50,000
|
| 691 |
+
But we can also declare a Java based resource bundles why we need them is a Java based resource.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:50,000 --> 00:14:53,000
|
| 695 |
+
Bundles have the only one biggest advantage.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:53,000 --> 00:15:00,000
|
| 699 |
+
You can get localized versions of objects because with the properties files, you can get on the string
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:00,000 --> 00:15:01,000
|
| 703 |
+
values.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:01,000 --> 00:15:10,000
|
| 707 |
+
But was Java based models you can get localized object associated was the key, but to be honest, not
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:10,000 --> 00:15:18,000
|
| 711 |
+
so often unique need to version of objects more often in your translations for your UI elements, but
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:18,000 --> 00:15:20,000
|
| 715 |
+
not localized objects.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:21,000 --> 00:15:29,000
|
| 719 |
+
Nevertheless, let me show you how you can create Java based resource bundles just in case you have
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:29,000 --> 00:15:35,000
|
| 723 |
+
to create a class with the name of your resource, bundle and language and country code, if needed.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:36,000 --> 00:15:43,000
|
| 727 |
+
This is exactly the case when you can violate Java naming convention and use underscores and class names
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:44,000 --> 00:15:46,000
|
| 731 |
+
because it will not work otherwise.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:46,000 --> 00:15:54,000
|
| 735 |
+
In case you will not use underscores, this clause should extend least resource bundle abstract class
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:54,000 --> 00:15:58,000
|
| 739 |
+
and you should override gut contents massive.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:58,000 --> 00:16:02,000
|
| 743 |
+
This should return multidimensional array matches.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:02,000 --> 00:16:06,000
|
| 747 |
+
Each array in this multidimensional array is a key value pair.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:07,000 --> 00:16:07,000
|
| 751 |
+
That's it.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:08,000 --> 00:16:11,000
|
| 755 |
+
Let's get back to our servicemen demo.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:12,000 --> 00:16:18,000
|
| 759 |
+
I change local and their attention after changing local and its resource bundle each time in the resource
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:18,000 --> 00:16:20,000
|
| 763 |
+
bundle would be updated.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:21,000 --> 00:16:26,000
|
| 767 |
+
And now I can extract object by call and get object massive and passing key.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:27,000 --> 00:16:31,000
|
| 771 |
+
After that, we can cast objects manually if we need.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:32,000 --> 00:16:39,000
|
| 775 |
+
Also, in case I forgot what keys are available, I can extract the key set of all keys.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:40,000 --> 00:16:44,000
|
| 779 |
+
You can explore API officers bundle by your own.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:45,000 --> 00:16:48,000
|
| 783 |
+
You would find awesome masses if they use a for you.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:49,000 --> 00:16:56,000
|
| 787 |
+
But I really believe I highlighted the most important masses like most likely you are going to use in
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:56,000 --> 00:16:56,000
|
| 791 |
+
practice.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:57,000 --> 00:17:03,000
|
| 795 |
+
And in case you have any questions, you can ask them in comments to the video, and I will be happy
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:03,000 --> 00:17:04,000
|
| 799 |
+
to answer.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:05,000 --> 00:17:10,000
|
| 803 |
+
One more important thing to know is priority for select and offer source bundles.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:10,000 --> 00:17:16,000
|
| 807 |
+
In the beginning, the application of the look for the file since across most suitable for the local
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:16,000 --> 00:17:24,000
|
| 811 |
+
you ask for, it starts with the most specific name that is one contained in a country language.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:25,000 --> 00:17:29,000
|
| 815 |
+
Then it goes to more general is there is no much.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:29,000 --> 00:17:31,000
|
| 819 |
+
It falls back to the default local.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:32,000 --> 00:17:43,000
|
| 823 |
+
Let's imagine that we have a local set in our app Zip or two musical and what my labels will rule my
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:43,000 --> 00:17:48,000
|
| 827 |
+
label's route and my labels is that this our default one.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:49,000 --> 00:17:56,000
|
| 831 |
+
We should keep in mind that each name represents both Jawa and Properties files, but the pool or if
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:56,000 --> 00:18:04,000
|
| 835 |
+
you will go, was Java bundles once there is no suitable file, a missing resource, exceptions thrown.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:05,000 --> 00:18:07,000
|
| 839 |
+
All what I wanted to share with you today.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:08,000 --> 00:18:10,000
|
| 843 |
+
Let's recap what we have announced today.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:11,000 --> 00:18:16,000
|
| 847 |
+
They will run what internationalization and localization is.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:16,000 --> 00:18:19,000
|
| 851 |
+
Also, you know, the difference between these two terms.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:20,000 --> 00:18:23,000
|
| 855 |
+
One examples we learnt how to work was no code class.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:24,000 --> 00:18:28,000
|
| 859 |
+
You saw how to format numbers, currencies and dates.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:29,000 --> 00:18:36,000
|
| 863 |
+
And at the end of the lesson we learned how to work was properties based on Java based resource bundles.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:37,000 --> 00:18:39,000
|
| 867 |
+
Thanks a lot for your attention.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:39,000 --> 00:18:42,000
|
| 871 |
+
Have a great day and see you in the next lesson.
|
| 872 |
+
|
41 - I18N & L10N/external-links.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
002 Source-code-examples-from-the-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/l18ni10n
|
42 - ===== Java Core Interview Preparation =====/001 How to be prepared for the interview.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>How to be prepared for the interview</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">How to be prepared for the interview</div>
|
| 65 |
+
<div class="article-asset-container"><p>I gathered for you the most popular questions during the Java Interview in JAVA CORE topic. How you can be prepared for the interview?</p><p><br></p><p>Just read the question first. Try to answer the question by yourself. After that, compare your answer with the answer provided. Remember, that this is just a reference to the answer. Because sometimes the topic is big, and you can go really deep with your answer. In case you feel like you don’t understand what the answer is about - feel free to get back in the course and review the relevant section, and relevant lesson one more time.</p><p><br></p><p>Also, you are always welcome to ask your questions and I will be happy to answer. I’m sure that these questions will help you to be prepared for the JAVA CORE interview. You need to be ready to answer perfectly on these questions.</p><p><br></p><p>In case there are questions that you don't know the answers to, please, feel free to check my full and the most complete course "Java From Zero to First Job".</p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/002 Part 1 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 1 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 1 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>HOW IS JRE, JVM AND JDK ARE DIFFERENT?</strong></p></li></ul><p><br></p><p>JRE in short - to make Java application run. Java Runtime Environment (abbr. JRE) - the minimum virtual machine implementation required to run Java applications without a compiler and other development tools. It consists of a virtual machine - Java Virtual Machine and a Java class library.</p><p>JDK in short - for programming. Java Development Kit (abbreviated as JDK) is a free Java application development kit distributed by Oracle Corporation (formerly Sun Microsystems), which includes the Java compiler (javac), standard Java class libraries, examples, documentation, various utilities, and the Java runtime environment( JRE).</p><p>Java Virtual Machine (abbreviated Java VM, JVM) - Java virtual machine - the main part of the Java execution system, the so-called Java Runtime Environment (JRE). The Java Virtual Machine interprets the Java Bytecode previously generated from the Java program source code by the Java Compiler (javac). The JVM can also be used to execute programs written in other programming languages.</p><p><br></p><ul><li><p><strong>DESCRIBE ACCESS MODIFIERS IN JAVA.</strong></p></li></ul><p><br></p><p>Java has the following access modifiers:</p><ul><li><p>private: (used in constructors, inner classes, methods and class fields) - Access is allowed only in the current class.</p></li><li><p>default (package-private): (used in classes, constructors, interfaces, inner classes, methods and class fields) - Package level access. If the class is declared like this, it will only be available within the package.</p></li><li><p>protected: (used in constructors, inner classes, methods, and class fields) An access modifier at the package level and in the inheritance hierarchy.</p></li><li><p>public: (used in classes, constructors, interfaces, inner classes, methods and class fields) - Public access modifier, available to everyone.<br><br></p></li></ul><p>The sequence of modifiers in descending order of privacy level: private, default ,protected, public).</p><p><br></p><ul><li><p><strong>HOW DOES AN ABSTRACT CLASS DIFFER FROM AN INTERFACE? WHEN WOULD YOU USE AN ABSTRACT CLASS AND WHEN WOULD YOU USE THE INTERFACE?</strong></p></li></ul><p><br></p><p>An abstract class is a class that is marked "abstract" and may or may not contain abstract methods. An instance of an abstract class cannot be instantiated. A class that inherits from an abstract class may or may not implement abstract methods. In case child class doesn’t implement all abstract methods, then it must also be abstract. Also, if the inheritor class overrides the method implemented in the abstract parent class, it can be overridden with the abstract modifier! That is, to abandon the implementation. Accordingly, this class must also be abstract as well.</p><p><br></p><p>As for the interface, it contains only abstract methods and constants, this was the case before the release of Java 8. Starting with Java 8, in addition to abstract methods, we can also use standard methods (default methods) and static methods (static methods) in interfaces.</p><p>A Default method in an interface is a method in an interface with default logic that is not required to be defined in the implementation of that interface.</p><p>Static methods in an interface are essentially the same as static methods in an abstract class.</p><p><br></p><p>When implementing an interface, a class must implement all methods of the interface. Otherwise, the class must be marked as abstract. An interface can also contain inner classes. And no abstract methods in them.</p><p><br></p><p>Also, always remember that you can extend only one class in Java, but you can implement multiple interfaces.</p><p><br></p><p>What to use: Interface or Abstract class?</p><p>An abstract class is used when we need some kind of default implementation. An interface is used when a class needs to specify specific behavior. Often an interface and an abstract class are combined, i.e. implement an interface in an abstract class to specify the default behavior and implementation.</p><p><br></p><p><br></p><ul><li><p><strong>CAN AN OBJECT ACCESS A PRIVATE CLASS VARIABLE? IF YES, HOW?</strong></p></li></ul><p><br></p><p>In general, a private class variable can only be accessed within the class in which it is declared. Private variables can also be accessed through the Java Reflection API.</p><p><br></p><p><br></p><ul><li><p><strong>IS IT POSSIBLE TO OVERLOAD A STATIC METHOD?</strong></p></li></ul><p><br></p><p>Static methods can be overloaded by non-static methods and vice versa - without restrictions. But there is no point in overriding a static method.</p><p><br></p><p><br></p><ul><li><p><strong>TELL ME ABOUT INTERNAL CLASSES. WHEN WILL YOU USE THEM?</strong></p></li></ul><p><br></p><p>An inner class is a class that exists within a class or interface. In doing so, it gains access to all fields and methods of its outer class.</p><p>What can it be used for? For example, to provide some additional class logic and encapsulate it. Although the use of inner classes complicates the program, it is recommended to avoid their use.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN AN INSTANCE VARIABLE AND A STATIC VARIABLE? GIVE AN EXAMPLE.</strong></p></li></ul><p><br></p><p>Static variables are initialized when the class is loaded by the classloader, and do not depend on the object. An instance variable is initialized when the class is created.</p><p>Example: For example, we need a global variable for all objects of a class, such as the number of visits by users of a particular article on the Internet. Each time an article is visited, a new object is created and the visits variable is incremented. The visits variable is a static variable that remains the same for all instances of the same class.</p><p><br></p><p><br></p><ul><li><p><strong>TELL ABOUT CLASS LOADERS AND ABOUT DYNAMIC LOADING OF CLASSES.</strong></p></li></ul><p><br></p><p>Any class used in a Java program has somehow been loaded into the program context by some kind of loader. All Java virtual machines include at least one class loader, the so-called base loader. It loads all the main classes, these are classes from rt.jar. It is interesting that this loader is not related to the program in any way, that is, we cannot get the name of the loader from java.lang.Object, for example, the getClassLoader() method will return null to us.</p><p><br></p><p>The next loader is the extension loader, it loads classes from $JAVA_HOME/lib/ext.</p><p><br></p><p>Next in the hierarchy is the system loader, it loads the classes, the path to which is specified in the classpath variable. For example, let's say that we have a custom class MyClass and we use it. How is it loading...</p><ul><li><p>First, the system loader tries to find it in its load cache; if found, the class is successfully loaded, otherwise, the load control is transferred to the extension loader, it also checks its load cache and, if unsuccessful, transfers the task to the base loader. It checks the cache and in case of failure tries to download it, if the download was successful - the download is complete. If not, it transfers control to the extension loader. The extension loader attempts to load the class and, if it fails, passes this task to the system loader. The system loader tries to load the class, and if it fails, a java.lang.ClassNotFoundException is thrown.</p></li></ul><p><br></p><p>This is how class loading works in Java. The so-called delegation of loading.</p><p><br></p><p>If there are custom loaders in the system, then they must be inherited from the java.lang.ClassLoader class.</p><p><br></p><ul><li><p><strong>What is static and what is dynamic class loading?</strong></p></li></ul><p><br></p><p>Static class loading occurs when using the "new" operator.</p><p>Dynamic loading occurs "on the fly" during program execution using the static class method Class.forName(class name). What is dynamic loading for? For example, we do not know what class we need and make a decision during the execution of the program by passing the class name to the static forName() method.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/003 Part 2 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 2 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 2 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHY DO SOME INTERFACES DON'T DEFINE METHODS AT ALL?</strong></p></li></ul><p><br></p><p>These are the so-called interfaces - markers. They simply indicate that the class belongs to a particular group of classes. For example, the Clonable interface indicates that a class supports the cloning mechanism.</p><p>The degree of abstraction in this case is brought to the absolute.</p><p>Marker interfaces in Java examples:</p><ul><li><p>Searilizable interface</p></li><li><p>Cloneable interface</p></li><li><p>Remote interface</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>TELL ME ABOUT JAVA MEMORY MODEL?</strong></p></li></ul><p><br></p><p>In Java, memory is arranged as follows, there are two types:</p><ul><li><p>heap</p></li><li><p>stack</p></li></ul><p><br>A heap consists of a static context and the heap itself</p><p>Let's move on to the heap. The heap consists of two parts:</p><ul><li><p>New heap</p></li><li><p>old heap</p></li></ul><p><br></p><p>The new heap, in turn, consists of two parts:</p><ul><li><p>Eden (let's call it the first) heap</p></li><li><p>Survival heap</p></li></ul><p><br></p><p>Short description:</p><ul><li><p>Eden Space (heap) - memory will be allocated in this area for all objects created from the program. Most of the objects do not live long (iterators, temporary objects used inside methods, etc.), and are deleted during garbage collections - these are areas of memory that are not moved to other areas of memory. When a given region fills up (i.e., the amount of allocated memory in this region exceeds some specified percentage), the GC performs a minor garbage collection. Compared to a full garbage collection, it takes little time, and only affects this area of memory - it cleans up obsolete Eden Space objects and moves the surviving objects to the next area.</p></li><li><p>Survivor Space (heap) - objects from the previous one are moved here after they have survived at least one garbage collection. From time to time, long-lived objects from this area move to Tenured Space.</p></li><li><p>Tenured (Old) Generation (heap) - Long-lived objects accumulate here (large high-level objects, singletons, resource managers, etc.). When this area fills up, a full, major collection is performed, which processes all objects created by the JVM.</p></li><li><p>Permanent Generation (non-heap) - This is where the meta-information used by the JVM (used classes, methods, etc.) is stored.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE MAIN DIFFERENCE BETWEEN STRING, STRINGBUFFER, STRINGBUILDER?</strong></p></li></ul><p><br></p><p>String can be used to create immutable objects. That is, for adding data to an already existing string, a new string object is created.</p><p>StringBuffer and StringBuilder can change and adding a string. These operations are not that expensive in terms of memory. The first is synchronized, the second is not. This is their only difference.</p><p>True, if we need to make a substring of a string, then it is better to use String, since its character array does not change and is not created anew for a new string. But in StringBuffer and StringBuilder, a new array of characters is created to create a substring.</p><p><br></p><p><br></p><ul><li><p><strong>TELL ME ABOUT JAVA I/O STREAMS</strong></p></li></ul><p><br></p><p>There are two types of I/O streams:</p><ul><li><p>byte stream (InputStream and OutputStream);</p></li><li><p>character stream (Reader and Writer);</p></li></ul><p><br></p><p>These are all abstract classes - decorators, to which additional functionality can be added, for example:</p><ul><li><p>InputStream in = new FileInputStream(new File("file.txt"));</p></li></ul><p>In this case we added additional functionality of reading the data from the file.<br><br></p><p><br></p><ul><li><p><strong>WHAT IS HEAP AND STACK MEMORY IN JAVA?</strong></p></li></ul><p><br></p><p>Java Heap (heap) - a dynamically allocated memory area created when the JVM starts. Used by Java Runtime to allocate memory for objects and JRE. The creation of a new object also happens in the heap. This is where the garbage collector works: it frees memory by deleting objects that do not have any references. Any object created in the heap is globally accessible and can be referenced from any part of the application.</p><p><br></p><p>Key things to remember:</p><ul><li><p>All objects live in the heap and get there when they are created.</p></li><li><p>An object consists of class fields and methods.</p></li><li><p>a place is allocated in the heap for the object itself, the amount of allocated memory depends on the fields, if your class field, for example, is an int variable, then it does not matter if you initialize it as "0" or as "1000000" - the object will occupy its own bits, + as many bytes as the int type (+32 bits) can hold, and so on with each field.</p></li></ul><p>Stack memory in Java works according to the LIFO (Last-In-First-Out) scheme. Whenever a method is called, a new block is created in the stack memory that contains the primitives and references to other objects in the method, locating in RAM and reaching the processor via the stack pointer. As soon as the method ends, the block is also unused, thus providing access to the next method. Stack memory is much smaller than heap memory.</p><p><br></p><p>Key things to remember:</p><ul><li><p>All methods live on the stack and get there when called.</p></li><li><p>Variables in methods also have stack memory because they are local.</p></li><li><p>If an object is created in the method, then it is placed on the heap, but its reference will still be on the stack, and after the method leaves the stack, the object will become a victim of the garbage collector, since the strong reference to it is lost, and it will be impossible to get from the main program stack to such an object.</p></li></ul><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES THE GARBAGE COLLECTOR WORK?</strong></p></li></ul><p><br></p><p>Firstly, it is worth saying that the garbage collector has several algorithms for working, it is not one.</p><p><br></p><p>When is memory cleared? If the memory in the First heap is completely full, then the garbage collector goes there and does its job. Which one depends on the circumstances.</p><p><br></p><p>For example, if there is a lot of garbage in the first heap (i.e. objects with a null reference), then the garbage collector marks these objects, further, those that remain with references, he transfers them to the Surviving heap, and in the first heap, he simply deletes everything.</p><p><br></p><p>The situation is different, if in the first heap there is little garbage, but a lot of work objects. What does the garbage collector do in this case? It marks the garbage, removes it, and composes the remaining objects.</p><p><br></p><p>It should also be noted that when there is not enough space in the Surviving heap, objects are transferred to the old heap, as a rule, long-lived objects are stored there.</p><p><br></p><p>It should also be noted that the garbage collector itself is called periodically, and not only when there is not enough memory.</p><p><br></p><p><br></p><ul><li><p><strong>TELL ABOUT TYPE CASTING. WHEN DO YOU RECEIVE CLASSCASTEXCEPTION?</strong></p></li></ul><p><br></p><p>Type casting is setting the type of a variable or object to something other than the current type. There are two types of cast in jew:</p><ul><li><p>automatic</p></li><li><p>not automatic</p></li></ul><p><br></p><p>Automatic happens for example in such cases:</p><p>byte->short->int->long->float->double</p><p>that is, if we extend the type, then no explicit conversion is required, the cast happens automatically. If we are narrowing, then it is necessary to explicitly specify the type conversion.</p><p><br></p><p>In the case of objects, we can automatically cast from the child type to the parent, but not vice versa, then a ClassCastException will be thrown.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A STATIC CLASS, WHAT ARE THE FEATURES OF ITS USE?</strong></p></li></ul><p><br></p><p>A static class can only be an nested class (a class definition is placed inside another class). An object of an ordinary inner class holds a reference to an object of the outer class. There is no such reference inside a static inner class.</p><p><br></p><p>That is: An object of an outer class is not needed to create an object of a static inner class. From an object of a static nested class, you cannot directly access the non-static members of the outer class. Also, ordinary inner classes cannot contain static methods and members.</p><p><br></p><p>Why do we need nested classes at all? Each inner class is able to independently inherit a specific implementation. Thus, the nested class is not restricted from being inherited in situations where the outer class already inherits the implementation. That is, it is like a solution to the problem of multiple inheritance.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF INNER CLASSES ARE THERE? WHAT ARE THEY USED FOR?</strong></p></li></ul><p><br></p><p>Nested classes exist within other classes. A normal class is a full member of a package. Nested classes, which have been available since Java 1.1, can be of four types:</p><ul><li><p>static nested classes</p></li><li><p>non-static inner classes</p></li><li><p>local classes</p></li><li><p>anonymous classes</p></li></ul><p><br></p><p>Static nested classes - like any other static method, it has access to any static methods of its outer class, including private ones. It cannot access non-static fields and methods of the enclosing class directly. It can only use them through a reference to an instance of the parent's class.</p><p><br></p><p>Non-static inner classes - classes that are declared inside other class and that are have access to the non-static properties of the outer parent class.</p><p><br></p><p>Local classes are classes that are defined in a block, which is a group of zero or more statements between balanced braces. You typically find local classes defined in the body of a method.</p><p><br></p><p>Anonymous Classes - These class types do not have a name and are only visible inside the block.</p><p><br></p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/004 Part 3 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 3 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 3 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>IS IT POSSIBLE TO CHANGE WHEN OVERRIDE THE METHOD:</strong></p><ol><li><p><strong>Access Modifier</strong></p></li><li><p><strong>return type</strong></p></li><li><p><strong>Argument type or number of arguments</strong></p></li><li><p><strong>Argument name</strong></p></li><li><p><strong>Change the order, quantity, or remove the throws section altogether?</strong></p></li></ol></li></ul><p><br></p><ol><li><p>Yes, if you expand (package -> protected -> public)</p></li><li><p>Yes, if Downcasting is performed (downcasting, conversion down the hierarchy), that is, the return type in the overridden method of the heir class must NOT be wider than in the parent class (Object -> Number -> Integer)</p></li><li><p>No, in this case, Overload occurs</p></li><li><p>Yes</p></li><li><p>It is possible to change the order. It is possible to remove the throws section from the method altogether, since it is already defined. It is also possible to add new exceptions that inherit from declared or runtime exceptions.</p></li></ol><p><br></p><p>Method overriding is valid when classes are inherited, i.e. a method with the same signature is declared in the descendant class as in the parent class. This means that this method has overridden the method of its superclass.</p><p><br></p><p>A few points about this:</p><ul><li><p>The access modifier in the method of the descendant class must be NOT narrower than in the parent class, otherwise there will be a compilation error.</p></li><li><p>The description of the exception in the overridden method of the descendant class must NOT be wider than in the parent class, otherwise a compilation error will appear.</p></li><li><p>A method declared as "private" in a parent class cannot be overridden!</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS AUTOBOXING?</strong></p></li></ul><p><br></p><p>Autoboxing/Unboxing - automatic conversion between Java primitive types and corresponding wrapper types (for example, between int - Integer). Having this capability reduces code because it eliminates the need to perform explicit type conversions in obvious cases.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE GENERICS?</strong></p></li></ul><p><br></p><p>"Java Generics" is a technical term for a set of language features that allow generic types and methods to be defined and used. Generic types or methods differ from regular ones in that they have typed parameters.</p><p><br></p><p>An example of generics or generic types is the collection library in Java. For example, the class LinkedList<E> is a typical generic type. It contains an E parameter that represents the type of elements that will be stored in the collection. Instead of just using LinkedList without saying anything about the type of element in the list, we can use LinkedList<String> or LinkedList<Integer>. Generic type objects are created by replacing parameterized types with real data types. A class of type LinkedList<E> is a generic type that contains a parameter E. Creating objects such as LinkedList<String> or LinkedList<Integer> are called parameterized types, while String and Integer are real argument types.</p><p><br></p><p>Using generics you can describe class, methods, properties on the different level of abstraction and after that usethe instances of the class parametrized by any type.</p><p><br></p><p><br></p><ul><li><p><strong>HOW ARE VARIABLES PASSED TO METHODS, BY VALUE OR BY REFERENCE?</strong></p></li></ul><p>In java, parameters are passed to methods by value, that is, copies of parameters are created and work is done with them in the method. In the case of primitive types, when passing a parameter, the variable itself will not change, since its value is simply copied to the method.</p><p><br></p><p>But when passing an object, a reference to the object is copied, that is, if we change the state of the object in the method, then the state of the object will also change after the method. But if we try to assign a new link to the object to this copy of the link, then the old link will not change.</p><p><br></p><p>We can say that everything in Java is passed by value. But in case with the reference types we pass the copy of the variable, and in case with primitive types we pass the copy of the primitive.</p><p><br></p><p><br></p><ul><li><p><strong>RULES FOR REDEFINITION OF THE OBJECT.EQUALS() METHOD</strong></p></li></ul><p><br></p><p>Use the == operator to test the object reference passed to the equals method. If the links match, return true. This is not necessary, rather for optimization, but can save time in case of "heavy" comparisons.</p><p><br></p><p>Use the instanceof operator to check the type of an argument. If the types do not match, return false.</p><p><br></p><p>Convert the argument to the correct type. Since we performed the check in the previous step, the transformation is correct.</p><p><br></p><p>Go through all the significant fields of the objects and compare them with each other. If all fields are equal, return true. Use == to compare simple types. For fields with object references, use equals.</p><p><br></p><p>Convert float to int with Float.floatToIntBits and compare with ==.</p><p><br></p><p>Convert double to long with Double.doubleToLongBits and compare with ==.</p><p><br></p><p>For collections, the above rules apply to each element in the collection. It is necessary to take into account the possibility of null fields/objects. The order in which fields are compared can have a significant impact on performance.</p><p><br></p><p>Once you've finished implementing equals, ask yourself if the method is symmetric, transitive, and consistent.</p><p><br></p><p>And one more rule: when overriding equals, always override hashCode for the sake of hash tables.</p><p><br></p><p><br></p><ul><li><p><strong>IF YOU WANT TO OVERRIDE EQUALS(), WHICH CONDITIONS SHOULD BE SATISFYED FOR AN OVERRIDED METHOD?</strong></p></li></ul><p><br></p><p>The equals() method denotes an object equivalence relationship. An equivalent relation is one that is symmetric, transitive, and reflexive.</p><ul><li><p>Reflexivity: for any non-null x, x.equals(x) will return true;</p></li><li><p>Transitivity: for any non-zero x, y, and z, if x.equals(y) and y.eqals(z) return true, then x.equals(z) also returns true;</p></li><li><p>Symmetry: For any non-zero x and y, x.equals(y) must return true if and only if y.equals(x) returns true.</p></li><li><p>Also for any non-null x, x.equals(null) should return false.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE RELATIONSHIP BETWEEN HASHCODE AND EQUALS?</strong></p></li></ul><p><br></p><p>Objects are equal when a.equals(b)=true and a.hashCode==b.hashcode -> true</p><p><br></p><p>But it is not necessary for two different objects to return different hash codes (this situation is called a collision). This is possible because hashCode returns value of type int. And int value has its ranges, while the set of objects theoretically may be close to infinite.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT WILL HAPPEN IF EQUALS IS OVERRIDEN WITHOUT OVERRIDING OF HASHCODE? WHAT PROBLEMS COULD APPEAR?</strong></p></li></ul><p><br></p><p>The elements in the hashtables would be not possible to find in Hash tables data structures, such as HashMap, HashSet.</p><p><br></p><p>The fact is that for a quick search, the hash table based data structure calculates the hashCode for each element to define the backet where to put element. It is also uses hashCode() method to find the backet where the element is located when it is time to retrieve the element. Once element is found, it is compared with the element that we used as a search criteria via equals() method. That’s why we can state that equals() and hashCode() works together and that’s why it is important to override hashCode() method too.</p><p><br></p><p><br></p><ul><li><p><strong>ARE THERE ANY RECOMMENDATIONS ABOUT WHICH FIELDS SHOULD BE USED IN HASHCODE CALCULATION?</strong></p></li></ul><p><br></p><p>Yes, there are. It is necessary to use unique, preferably primitive fields, such as id, uuid, for example. Moreover, if these fields are involved in the calculation of hashCode, then you need to use them when performing equals.</p><p>General advice: choose fields that are very likely to differ. And use the same fields that you used in equals() method for comparison.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE HASHCODE() METHOD FOR?</strong></p></li></ul><p><br></p><p>There are collections (HashMap, HashSet) that use the hash code as the basis for working with objects. And if the hash for equal objects is different, then the HashMap will have two equal values, which is an error. Therefore, it is necessary to override the hashCode() method appropriately.</p><p><br></p><ul><li><p>Hashing - converting an input data array of arbitrary length into an output bit string of a fixed length. Such transformations are also called hash functions or convolution functions, and their results are called hashes or hash codes.</p></li><li><p>Hash table is a data structure that implements the interface of an associative array, namely, it allows you to store pairs (key, value) and perform at least three main operations: the operation of adding a new pair, the operation of searching and the operation of deleting a pair by key.</p></li></ul><p><br></p><p>The execution of an operation in a hash table begins with the calculation of the hash function of the key. The resulting hash value i = hash(key) acts as an index into the array H. Then the operation performed (add, remove or lookup) is redirected to the object stored in the corresponding cell in the array H[i].</p><p>One of the methods for constructing a hash function is the division method with a remainder (division method) is that the key k is assigned the remainder of dividing k by m, where m is the number of possible hash values.</p><p><br></p><p><br></p><ul><li><p><strong>RULES FOR REDEFINITION OF THE OBJECT.HASHCODE() METHOD.</strong></p></li></ul><p><br></p><p>The implementation of hashCode() uses a few simple rules. First of all, when calculating the hash code, you should use the same fields that are compared in equals() method. This, firstly, will give equality of hash codes for equal objects, and secondly, the resulting value will be distributed in exactly the same way as the original data. Theoretically, you can make the hash code always equal to 0, and this will be a completely legal implementation. Another thing this will not bring you any sens and any value.</p><p><br></p><p>Even though the hash codes of equal objects should be equal, the reverse is not true! Two unequal objects can have equal hash codes.</p><p><br></p><p>Another important requirement for the hashCode() method is the speed of calculation, because this has to be done very often. Therefore, in some cases it makes sense to calculate the hash code in advance and simply issue it on request. First of all, this should be done when the calculation is long, heavy, and the object is immutable.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/005 Part 4 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 4 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 4 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>TELL ABOUT OBJECTS CLONING. WHAT IS THE DIFFERENCE BETWEEN SHALLOW AND DEEP CLONING?</strong></p></li></ul><p><br></p><p>For an object to be cloneable, it must implement the Cloneable(marker) interface. The use of this interface affects the behavior of the "clone" method of the Object class. In this way</p><p>myObj.clone() will create a clone of our object for us, but this clone will be superficial.</p><p><br></p><p>What does superficial mean? This means that only primitive class fields are cloned, reference fields are not cloned!</p><p><br></p><p>In order to perform deep cloning, it is necessary to override the clone() method in the cloned class and clone the variable fields of the object in it.</p><p><br></p><p><br></p><ul><li><p><strong>RULES FOR REDEFINITION OF THE OBJECT.CLONE() METHOD.</strong></p></li></ul><p><br></p><p>The clone() method in Java is used to clone objects. Because Java works with objects using references, then simple assignment is not enough here, because in this case only the address is copied, and we will get two references to the same object, and this is not what we need. The copy mechanism provides the clone() method of the Object class.</p><p>clone() acts like a copy constructor. It usually calls the clone() method of the superclass, and so on. until it gets to Object.</p><p><br></p><p>The clone() method of the Object class creates and returns a copy of the object with the same field values. Object.clone() throws CloneNotSupportedException if you are trying to clone an object that does not implement the Cloneable interface. The default implementation of the Object.clone() method performs a shallow copy. If you need a full / deep (deep) copy of a class, then in the clone() method of this class, after obtaining a clone of the superclass, you need to copy the necessary fields.</p><p><br></p><p>One of the disadvantages of the clone() method is the fact that the type returned is Object, so a downcast is required. However, since Java 1.5, when overriding a method, you can narrow the return type.</p><p><br></p><p>A few words about clone() and final fields.</p><p><br></p><p>The clone() method is incompatible with final fields. If you try to clone a final field the compiler will stop you. The only solution is to drop final.</p><p><br></p><p><br></p><ul><li><p><strong>WHERE AND HOW CAN YOU USE A PRIVATE CONSTRUCTOR?</strong></p></li></ul><p><br></p><p>For example, you need to use private constructor in a Singleton pattern. In the same class, a static method is created. Where an instance of the class is created, of course, if it is not already created, then it is simply returned by the method.</p><p><br></p><ul><li><p><strong>WHAT IS A DEFAULT CONSTRUCTOR?</strong></p></li></ul><p><br></p><p>In Java, if there are no explicitly defined constructors in a class, then the compiler uses an implicitly defined default constructor, which is similar to a "pure" default constructor. The default constructor is a fairly simple construct, which boils down to creating a constructor for a type with no parameters. So, for example, if a user-defined constructor is not declared when declaring a non-static class (it doesn’t matter if it has parameters or without them), then the compiler will independently generate a constructor without parameters. Some programmers explicitly set a default constructor out of habit so they don't forget later, but this is not necessary.</p><p><br></p><p>In Java, if the derived class does not explicitly call the base class constructor (in Java, using super() in the first line), then the default constructor is implicitly called. If the base class does not have a default constructor, then this is considered an error.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE FINAL, FINALLY AND FINALIZE?</strong></p></li></ul><p><br></p><p><strong>final </strong>- You cannot inherit from a final class. You cannot override the final method. You cannot change the value of the final field.</p><p><strong>finally </strong>- used in error handling, always called even if an error occurs (except System.exit(0)). Useful for freeing up resources.</p><p><strong>finalize()</strong> - starting from the Java 9 it is a deprecated method of an Object class. It is called before the garbage collector will free the memory. It is not recommended to use it to free up system resources, since it is not known when the garbage collector will clean up. In general, few people use this method. The only thing you can use this method to close a resource is that it should run for the duration of the program and close when it ends. You can also use the method to protect against the so-called "fools", check whether the resources are freed, if not, then close them.</p><p><br></p><p><br></p><ul><li><p><strong>DESCRIBE THE HIERARCHY OF EXCEPTIONS</strong></p></li></ul><p><br></p><p>All exception classes extend the Throwable class, which is a direct extension of the object class.</p><p><br></p><p>The Throwable class and all its extensions traditionally have two constructors:</p><ul><li><p>Throwable() - default constructor;</p></li><li><p>Throwable(String message) - the created object will contain an arbitrary message message.</p></li></ul><p><br></p><p>The message written in the constructor can then be retrieved using the getMessage() method. If the object was created by the default constructor, then this method will return null.</p><p>The toString method returns a brief description of the event, which is what worked in the previous listings.</p><p><br></p><p>Three methods print messages about all methods encountered along the path of the "flight" of the exception:</p><p><br></p><ul><li><p>printstackTrace() - prints messages to standard output, usually the console;</p></li><li><p>printStackTrace(PrintStream stream) - prints messages to the byte stream stream;</p></li><li><p>printStackTrace(PrintWriter stream) - prints messages to the character stream stream.</p></li></ul><p><br></p><p>The Throwable class has two direct descendants, the Error and Exception classes. They do not add new methods, but serve to separate exception classes into two large families - the family of error classes (error) and the family of exception classes themselves (exception).</p><p><br></p><p>Error classes that extend the Error class indicate difficult situations in the Java Virtual Machine. Their processing requires a deep understanding of all the intricacies of the JVM. It is not recommended to perform it in a regular program. It is not even advised to throw errors with the throw statement. You should not make your exception classes extensions of the Error class or some subclass of it.</p><p><br></p><p>Error class names, by convention, end with the word Error.</p><p><br></p><p>Exception classes that extend the Exception class mark the occurrence of a common abnormal situation that can and should even be handled. Such exceptions should be thrown with the throw statement. There are a lot of exception classes, more than two hundred. They are scattered throughout literally all JDK packages. In most cases, you will be able to pick up a ready-made exception class to handle exceptions in your program. If you wish, you can create your own exception class by extending the Exception class or any of its subclasses.</p><p><br></p><p>Among the exception classes, the RuntimeException class stands out - a direct extension of the Exception class. In it and its subclasses, exceptions are noted that occurred during the operation of the JVM, but are not as serious as errors. They can be processed and thrown away, extended with their own classes, but it is better to entrust this to the JVM, since most often this is just a bug in the program that needs to be fixed. The peculiarity of exceptions of this class is that they do not need to be marked in the method header with the throws mark.</p><p><br></p><p>Exception class names, by convention, end with the word Exception.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT KINDS OF EXCEPTIONS IN JAVA DO YOU KNOW, HOW THEY DIFFER?</strong></p></li></ul><p><br></p><p>All exceptional situations can be divided into two categories: checked and unchecked.</p><p><br></p><p>All exceptions thrown from Throwable can be divided into three groups. They are defined by three base types: the Throwable descendants, the Error and Exception classes, and the Exception descendant, RuntimeException.</p><p>Exceptions that are descended from Exception class (and are not descendants of RuntimeException ) are checkable. Those. at compile time, it is checked whether the handling of possible exceptions is provided. As a rule, these are errors related to the program environment (network, file I/O, etc.), which can occur regardless of whether the code is written correctly or not. For example, opening a network connection or a file may result in an error, and the compiler requires the programmer to take some action to handle possible problems. This increases the reliability of the program, its stability in case of possible failures.</p><p><br></p><p>Exceptions thrown from RuntimeException are unchecked and are not required to be handled by the compiler.</p><p><br></p><p>As a rule, these are program errors that should not occur if coded correctly (for example, IndexOutOfBoundsException - array bounds out of bounds, java.lang.ArithmeticException - division by zero). Therefore, in order not to clutter up the program, the compiler leaves it up to the programmer to handle such exceptions and whether developer would like to handle such exceptions using try-catch blocks.</p><p><br></p><p>Exceptions thrown from Error are not checked either. They are intended to notify the application about the occurrence of a fatal situation, which is almost impossible to eliminate programmatically (although formally a handler is allowed). They may indicate program errors, but they are usually unrecoverable problems at the JVM level. Examples include StackOverflowError (stack overflow), OutOfMemoryError (out of memory).</p><p><br></p><p>Methods whose code can throw checked exceptions must either handle them themselves, or the method header must contain the throws keyword with a list of unhandled checked exceptions. This rule does not apply to unchecked errors.</p><p><br></p><p>An overridden method cannot extend the list of possible exceptions of the original method.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS CHECKED AND UNCHECKED EXCEPTION?</strong></p></li></ul><p><br></p><p>Checked exceptions are those that should be handled by the catch block or described in the method signature. Unchecked may not be handled and declared.</p><p><br></p><ul><li><p>Unchecked exceptions in Java - inherited from RuntimeException, Checked - from Exception.</p></li></ul><p><br></p><p>An example of an unchecked exception is NullPointerException, a checked exception is IOException.</p><p><br></p><p><br></p><ul><li><p><strong>HOW TO CREATE YOUR UNCHECKED EXCEPTION?</strong></p></li></ul><p><br></p><p>Inherit from RuntimeException.</p><p><br></p><ul><li><p><strong>DESCRIBE THE WORK OF THE TRY-CATCH-FINALLY BLOCK.</strong></p></li></ul><p>If one of the catch blocks fires, then the remaining blocks in this try-catch construct will not be executed.</p><p><br></p><p>Exceptions do not have the transactional property - actions performed in the try block before the exception occurs are not canceled after it occurs.</p><p><br></p><p>Finally block is executed even in case there was a mistake in the catch block, or even in case there is no catch block. Definately, there are some exceptions when finally block will not be executed till the end. Such cases for example: in case we call System.exit(0) and stoped virtual machine, or finally block was part of the daemon thread execution and the parent thread is stopped and edge cases like this.</p><p><br></p><p>There is also possibility to add multiple exceptions into the catch statement of catch block.</p><p><br></p><p><br></p><ul><li><p><strong>IS IT POSSIBLE TO USE A TRY-FINALLY BLOCK (WITHOUT CATCH)?</strong></p></li></ul><p><br></p><p>try can be paired with finally, without catch. It works exactly the same - after exiting the try block, the finally block is executed. This can be useful, for example, in the following situation. When you exit the method, you need to perform some action. And return in this method is in several places. It is not practical to write the same code before each return. It is much easier and more efficient to put the main code in a try and the exit code in a finally.</p><p><br></p><p>Or in case you need to close some resources - you can do this in finally block.</p><p><br></p><ul><li><p><strong>IS THE FINALLY BLOCK ALWAYS EXECUTED?</strong></p></li></ul><p><br></p><p>Not always, for example in the following situations:</p><ul><li><p>There are daemon threads - threads that provide some services, working in the background while the program is running, but are not an integral part of it. Thus, when all non-daemon threads terminate, the program terminates. In daemon threads, the finally block is not executed, they are interrupted abruptly.</p></li><li><p>System.exit(0)</p></li><li><p>if an exception occurs in the finally block and there is no handler, then the remaining code in the finally block may not be executed.</p></li></ul></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/006 Part 5 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 5 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 5 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT ARE THE FEATURES OF THE STRING CLASS? WHAT THE INTERN() METHOD DOES.</strong></p></li></ul><p><br></p><p>The internal state of the String class cannot be changed after it has been created, i.e. this class is immutable so when you write String str = "One" + "Two"; the third String “OneTwo” is created! object of class String.</p><p><br></p><p>It cannot be inherited from because the String class is declared final: public final class String</p><p><br></p><p>The String class has a public String intern() method that returns a string in its canonical representation from the internal string pool maintained by the JVM, it is needed to use == instead of String.equals().</p><p><br></p><p>Why you may want to do this? It is clear that the reference comparison operator is much faster than a character-by-character string comparison.</p><p><br></p><p>They are mainly used where you have to compare many strings, for example, in some kind of XML parsers.</p><p><br></p><p>And in general on increase in productivity still a question. For the intern() method should then be faster than equals(), each time you call the intern() method, the string pool is searched for the presence of such a string, and if there is already one in the pool, then a reference to it is returned. They are compared through equals()</p><p><br></p><p><br></p><ul><li><p><strong>IS IT POSSIBLE TO INHERIT A STRING TYPE, WHY?</strong></p></li></ul><p><br></p><p>No, because String class if final. It has “final” modificator and can’t be extended.</p><p><br></p><p><br></p><ul><li><p><strong>DESCRIBE WHAT A "STRING POOL" IS</strong></p></li></ul><p><br></p><p>A string pool is a collection of strings that is stored in Java heap memory. We know that String is a special class in Java, and we can create objects of this class using the new operator just like we can create objects by providing a string value in double quotes.</p><p><br></p><p>String pooling is possible solely due to the immutability of strings in Java and the implementation of the idea of string interning.</p><p><br></p><p>The string pool helps save a lot of memory, but on the other hand, creating a string takes more time.</p><p><br></p><p>When we use double quotes to create a string, it first looks for a string in the pool with the same value, if found, it simply returns a reference, otherwise a new string is created in the pool, and then a reference is returned.</p><p><br></p><p>However, when we use the new operator, we force the String class to create a new string object, and then we can use the intern() method to put the string into the pool, or retrieve from the pool a reference to another String object with the same value.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHY IS A STRING A POPULAR KEY IN A HASHMAP IN JAVA?</strong></p></li></ul><p><br></p><p>Since strings are immutable, their hashcode is cached at the time of creation and does not need to be recomputed. This makes strings an excellent candidate for a key in a Map, and they process faster than other HashMap key objects. This is why strings are predominantly used as HashMap keys.</p><p><br></p><p>Also, the String object is immutable and you can’t lose the value that is associated with the String key because String key can’t be changed or modified.</p><p><br></p><p><br></p><ul><li><p><strong>CAN STRING ACCESS BE SYNCHRONIZED?</strong></p></li></ul><p><br></p><p>There is no sense in this because all objects of type String are immutable. If you want to work with mutable strings and synchronize access to them - then you need to use StringBuffer.</p><p><br></p><p><br></p><ul><li><p><strong>HOW CORRECTLY COMPARE THE STRING VALUES OF TWO DIFFERENT OBJECTS OF TYPE STRING AND STRINGBUFFER?</strong></p></li></ul><p><br></p><p>Bring them to the same type and compare.</p><p><br></p><ul><li><p><strong>WHY IS A STRING UNCHANGED AND FINALIZED IN JAVA?</strong></p></li></ul><p><br></p><p>There are several advantages to string immutability:</p><ul><li><p>The string pool is only possible because the string is immutable in Java, thus the virtual machine saves a lot of heap space since different string variables point to the same variable in the pool. If a string were not immutable, then string interning would not be possible, because if any variable changes its value, the rest of the variables referring to that string will also be affected.</p></li><li><p>If the string is mutable, then it becomes a serious security risk to the application. For example, the database username and password are passed as a string to obtain a database connection, and in socket programming, host and port details are passed as a string. Since the string is immutable, its value cannot be changed, otherwise any hacker could change the value of the link and cause security problems for the application.</p></li><li><p>Strings are used in the Java classloader and immutability ensures that the class is correctly loaded by the Classloader. For example, think about the class instance when you are trying to load the java.sql.Connection class, but the reference value is changed to myhacked.Connection class, which can do unwanted things to your database.</p></li><li><p>Since the string is immutable, its hashcode is cached at the time of creation and there is no need to calculate it again. This makes the string an excellent candidate for a Map key and will be faster to process than other HashMap keys. This is the reason why string is the most commonly used object used as a HashMap key.</p></li></ul><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/007 Part 6 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 6 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 6 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS REFLECTION?</strong></p></li></ul><p><br></p><p>Reflection is used to obtain or modify type information during program execution. This mechanism allows you to get information about classes, interfaces, fields, methods, constructors during program execution. You don't need to know the names of classes, methods, or interfaces. It also allows you to create new objects, execute methods, and get and set field values.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS INTERNATIONALIZATION, LOCALIZATION?</strong></p></li></ul><p><br></p><p>Internationalization (or i18n for short) is a way of building applications so that they can be easily adapted to different audiences speaking different languages.</p><p>Localization (for short - l10n) - adaptation of the application interface for several languages.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE ANNOTATIONS IN JAVA?</strong></p></li></ul><p><br></p><p>Annotations are a kind of meta tags that are added to code and applied to the declaration of packages, classes, constructors, methods, fields, parameters, and local variables.</p><p><br></p><p>Annotations always have some information and link this "additional data" and all the listed language constructs.</p><p><br></p><p>In fact, annotations are their additional modifiers, the use of which does not entail changes in the previously created code.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT FUNCTIONS DO ANNOTATIONS PERFORM?</strong></p></li></ul><p><br></p><p>The annotation performs the following functions:</p><ul><li><p>gives the necessary information to the compiler;</p></li><li><p>gives information to various tools for generating other code, configurations, etc.;</p></li><li><p>can be used while the code is running;</p></li></ul><p><br></p><p>The most common annotation that any programmer, even a beginner, has come across is @Override.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DO THE @RETENTION, @DOCUMENTED, @TARGET, AND @INHERITED ANNOUTATIONS DO?</strong></p></li></ul><p><br></p><p>These annotations have the following meaning:</p><ul><li><p>@Retention - this annotation is intended to be applied only as an annotation to other annotations, allows you to specify the life cycle of the annotation: will it be present only in the source code, in the compiled file, or will it also be visible during execution. Choosing the right type depends on how you want to use the annotation.</p></li><li><p>@Documented is a marker interface that tells the tool that the annotation should be documented.</p></li><li><p>@Target - This annotation specifies the type of declaration to which the annotation can be applied. Takes one argument, which must be a constant from the ElementType enumeration, it can be a field, method, type, etc. For example, to indicate that an annotation only applies to fields and local variables: @Targer({ ElementType.FIELD, ElementTyle.LOCAL_VARIABLE } )</p></li><li><p>@Inherited is a marker annotation that can be applied in another annotation declaration, it only applies to annotations that will be used in class declarations. Indicates that an annotation interface is automatically inherited. This annotation allows a super class annotation to be inherited in a subclass.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT DO THE @OVERRIDE, @DEPRECATED, @SAFEVARARGS AND @SUPPRESSWARNINGS ANNOUTATIONS DO?</strong></p></li></ul><p><br></p><p>These annotations are for:</p><ul><li><p>@Override is a marker annotation that can only be applied to methods. A method annotated with @Override must override a super class method.</p></li><li><p>@Deprecated - Indicates that the declaration is deprecated and should be replaced with a newer form.</p></li><li><p>@SafeVarargs is a marker annotation applied to methods and constructors. It specifies that no unsafe behavior associated with the variable number of arguments option is allowed. Applies only to variadic methods and constructors that are declared static or final.</p></li><li><p>@SuppressWarnings - This annotation specifies that one or more warnings that may be issued by the compiler should be suppressed.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT LIFE CYCLE OF AN ANNOTATION CAN BE SPECIFIED WITH @RETENTION?</strong></p></li></ul><p><br></p><p>There are 3 possible options to specify where the annotation will live. They are encapsulated in a java.lang.annotation.RetentionPolicy enum. These are SOURSE, CLASS, RUNTIME.</p><ul><li><p>SOURCE - annotation is contained only in the source file and discarded when compiling.</p></li><li><p>CLASS - stored in a file, however annotations are not available to the JVM at runtime.</p></li><li><p>RUNTIME - annotations are stored in a file at compile time and remain available to the JVM at run time.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>TO WHICH ELEMENTS IS IT POSSIBLE TO APPLY THE SUMMARY, HOW TO INDICATE IT?</strong></p></li></ul><p><br></p><p>In order to limit the use of an annotation, it must be annotated. There is a @Target annotation for this.</p><ul><li><p>@Target(ElementType.PACKAGE) - for packages only;</p></li><li><p>@Target(ElementType.TYPE) - for classes only;</p></li><li><p>@Target(ElementType.CONSTRUCTOR) - for constructors only;</p></li><li><p>@Target(ElementType.METHOD) - for methods only;</p></li><li><p>@Target(ElementType.FIELD) - only for class attributes (variables);</p></li><li><p>@Target(ElementType.PARAMATER) - only for method parameters;</p></li><li><p>@Target(ElementType.LOCAL_VARIABLE) - for local variables only.</p></li></ul><p><br></p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW TO CREATE YOUR OWN ANNOTATION?</strong></p></li></ul><p><br></p><p>Writing your annotation is not as difficult as it might seem.</p><p><br></p><p>In the place where we usually write class or interface, we have @interface written.</p><p><br></p><p>The structure is almost the same as for interfaces, only @interface is written.</p><ul><li><p>@interface - indicates that this is an annotation</p></li><li><p>default - says that the default method will return a certain value.</p></li></ul><p><br></p><p>The annotation is ready, now it can be used, and the annotation can also be configured. You can configure @Target and @Retention for this annotation</p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF ATTRIBUTES ARE ALLOWED IN ANOTATIONS?</strong></p></li></ul><p><br></p><p>Attributes can only have the following types:</p><ul><li><p>primitives</p></li><li><p>String</p></li><li><p>Class</p></li><li><p>enum</p></li><li><p>annotation</p></li><li><p>an array of elements of any of the above types</p></li></ul><p><br></p><p>The last point should be understood as the fact that only one-dimensional arrays are allowed.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT MECHANISMS ENSURE SAFETY IN JAVA TECHNOLOGY?</strong></p></li></ul><p><br></p><p>In Java technology, security is provided by the following three mechanisms:</p><ul><li><p>structural functionality of the language (for example, array bounds checking, the prohibition of unchecked type conversions, the absence of pointers, etc.).</p></li><li><p>access controls that determine the actions that are allowed or prohibited to be performed in the code (for example, whether the code can access files, transfer data over the network, etc.).</p></li><li><p>a digital signature mechanism that allows authors to use standard algorithms to authenticate their programs, and users to determine exactly who created the code and whether it has changed since it was signed.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS REFACTORING?</strong></p></li></ul><p><br></p><p>Refactoring is the process of changing the internal structure of a program without affecting its external behavior and with the aim of making it easier to understand how it works. Refactoring is based on a series of small equivalent (that is, behavior-preserving) transformations.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
42 - ===== Java Core Interview Preparation =====/008 Part 7 Java Core Interview Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 7 Java Core Interview Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 7 Java Core Interview Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><p><br></p><ul><li><p><strong>WHAT IS A STRINGJOINER?</strong></p></li></ul><p><br></p><p>StringJoiner is used to create a delimiter-separated sequence of characters that may (but need not) start with a prefix and end with a suffix.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE DEFAULT METHODS?</strong></p></li></ul><p><br></p><p>Starting with Java 8, we can use default methods and static methods in interfaces.</p><p>A default method is a method in an interface with default logic that is not required to be implemented during the implementation of the interface.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE STATIC METHODS IN INTERFACES?</strong></p></li></ul><p><br></p><p>Static methods in an interface are essentially the same as static methods in an abstract class.</p><ul><li><p>Static methods in an interface are part of the interface, we cannot use it on objects of the implementation class.</p></li><li><p>Static methods in an interface are good for providing helper methods like checking for null, sorting collections, etc.</p></li><li><p>Static methods in an interface help provide security by preventing classes that implement the interface from overriding them.</p></li></ul><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS OPTIONAL?</strong></p></li></ul><p><br></p><p>Optional is an object container, it can contain a value, or some type T, or just be null. It provides many useful methods to avoid adding repeated if null/notNull checks, allowing us to focus on what we want to do.</p><p><br></p><p>The isPresent() method returns true if the Optional instance contains a non-null value and false otherwise. The orElseGet() method contains a fallback mechanism to result if the Optional is null, accepting functions to generate a default value. The map() method transforms the current Optional value and returns a new Optional instance. The orElse() method is similar to orElseGet(), but instead of a function, it takes a default value.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS NASHORN?</strong></p></li></ul><p><br></p><p>Nashorn is a JavaScript engine developed entirely in Java by Oracle. It is designed to enable JavaScript code to be embedded in Java applications. Compared to Rhino, which is maintained by the Mozilla Foundation, Nashorn provides 2x to 10x better performance because it directly compiles the code in memory and passes the bytecode to the Java Virtual Machine. Nashorn can compile JavaScript code and generate Java classes that are loaded by a special loader. It is possible to call Java code directly from JavaScript.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS JJS IN JAVA</strong></p></li></ul><p><br></p><p>Nashorn comes with a jjs cmd utility that allows you to execute JavaScript directly in the console. jjs takes a list of JavaScript source files and runs them. To run the file, let's pass it as an argument to jjs:</p><ul><li><p>jjs fileName.js</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS LOCALDATETIME?</strong></p></li></ul><p><br></p><p>LocalDateTime combines LocaleDate and LocalTime together and contains the date and time, but without the time zone in the ISO-8601 calendar system. Time is stored with nanosecond precision, so LocalTime can store, for example, the value "13:45.30.123456789".</p><p><br></p><p>There are many useful methods like plusMinutes, plusHours, isAfter, toSecondOfDay, etc.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS ZONEDDATETIME?</strong></p></li></ul><p><br></p><p>ZonedDateTime is similar to java.util.Calendar. This is the most powerful class with complete information about the time context, including the time zone. It contains the date and time in the ISO-8601 calendar system.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
43 - == EXAM Java Standard Edition - Online Store - Task description and solution ==/001 Implement online store application.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Implement online store application</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Implement online store application</div>
|
| 65 |
+
<div class="article-asset-container"><p>Hello team,</p><p>If you follow the course, then you already know that we are in progress of implementation of our online shop. And with each new topic learned, I want you gradually implement more and more features. This time we are going to implement new features taking into account new topics that we've learned.</p><p>- As the basis for the project, let's take the last improvement that we did. It is located here - <a href="https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/template" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/template</a></p><p>- On top of template implement tasks described below.</p><p><br></p><p>1. Mail sender and mockito test</p><p>- Create MailSender interface. The interface has only one method - void sendEmail(String sendTo, String messageToSend);</p><p>- Create ResetPasswordService interface with one method - void resetPasswordForUser(User user);</p><p>Why for a user but not just for email? Because of potential scalability. Imagine that we will implement login via phone number? In this case we can find the user by his phone and send the password to his email. Or, we still can extract a user from storage and keep the same API. We would just need to implement a different implementation of service that will consider resetting via phone number. That's the reason why I recommend keeping User in API here.</p><p>- Create implementation of ResetPasswordService - DefaultResetPasswordService</p><p>- DefaultResetPasswordService uses instance of MailSender to send message to user email. Message should contain current user password.</p><p>- Create test with the help of Mockito that verifies that when we call resetPasswordForUser method, we send message to user's email, but not to different email, and message should contain current password of a user.</p><p>Commit on the github with solution of this task is here - <a href="https://github.com/AndriiPiatakha/learnit_java_core/commit/28b0bad9668222b175f7529a16c7465ea386e1df" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/learnit_java_core/commit/28b0bad9668222b175f7529a16c7465ea386e1df</a> <br>Solution is here - <a href="https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/solution" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/solution</a></p><p><br></p><p>2. Implement annotation for user validation.</p><p>- Create annotation @Validate</p><p>- This annotation will be used with class attributes of String type</p><p>- Annotation has one attribute that is called "pattern" - string value</p><p>- As a developer I can use annotation to add validation rules for string fields</p><p>- Create interface Validator with one method - boolean isValid(Object obj);</p><p>- Create implementation of Validator interface - DefaultValidator. When I call isValid method I receive true in case pattern specified in @Validate annotation matched with attribute values in particular fields, if not, then I return false.</p><p>- For demo purposes, you can mark with this annotation and with your pattern such fields in DefaultUser class - firstName, lastName and email. Come up with a regex pattern by yourself.</p><p>- Implement unit tests that demo the functionality</p><p>Commit on the github with solution of this task is here - https://github.com/AndriiPiatakha/learnit_java_core/commit/ae2949bde68d30cd3798d8c254f419d7b75f3308</p><p><br></p><p>3. Implement multithreading approach</p><p>- Implement additional menu option - Reset password</p><p>- After navigating on the reset menu, the user is asked to provide his email.</p><p>- Once a user submitted an email, we instantly showing him the message "Your password has been sent to your email. Please, check the mailbox. You will receive the email within the next 5 minutes".</p><p>- In parallel, we have a separate thread running that finds a user by email in our storage. And we use ResetPasswordService to send email in the background, while a user without any waiting time can navigate to different menus.</p><p><br></p><p>4. Implement I18N and L10N for the app.</p><p>- All text elements should support at least two languages</p><p>- There is a separate menu that is called “Change Language”. After selecting this menu, the user can select one of the languages for the user interface.</p><p>- After user changed language - All text items translated to different language automatically</p><p>The whole solution is here - <a href="https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/solution" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/exam/solution</a></p><p>Resource bundles are here - <a href="https://github.com/AndriiPiatakha/learnit_java_core/tree/master/resources/exam" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/learnit_java_core/tree/master/resources/exam</a></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
44 - Java New Versions/001 Java 8 Features (Lambda, Stream API, Optional, Effectively Final, etc.)_en.srt
ADDED
|
@@ -0,0 +1,1644 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:12,000
|
| 3 |
+
Hello dear students, I promised you to provide updates about new Java versions and new features.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:12,000 --> 00:00:16,000
|
| 7 |
+
In this lesson we are going to learn features from Java version eight.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:16,000 --> 00:00:22,000
|
| 11 |
+
I know that we learned a lot of Java eight features in my course Java from zero to first job, but probably
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:22,000 --> 00:00:27,000
|
| 15 |
+
you were not aware that these features are available just from Java eight.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:27,000 --> 00:00:32,000
|
| 19 |
+
And still, I believe this would be important to learn in order to structure your knowledge.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:33,000 --> 00:00:38,000
|
| 23 |
+
This lesson is going to be full of practical examples, because I plan to show you a new features on
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:38,000 --> 00:00:40,000
|
| 27 |
+
real examples.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:40,000 --> 00:00:42,000
|
| 31 |
+
Today we will review such features.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:43,000 --> 00:00:45,000
|
| 35 |
+
Interface, default and static methods.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:45,000 --> 00:00:47,000
|
| 39 |
+
Functional interfaces.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:47,000 --> 00:00:48,000
|
| 43 |
+
Lambda expressions.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:48,000 --> 00:00:49,000
|
| 47 |
+
Methods.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:49,000 --> 00:00:50,000
|
| 51 |
+
References.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:50,000 --> 00:00:56,000
|
| 55 |
+
Effectively final variables stream API in my course Java from zero to first job.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:56,000 --> 00:01:02,000
|
| 59 |
+
I even have separate section about functional programming in Java, where we learn some of these topics
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:02,000 --> 00:01:09,000
|
| 63 |
+
in details in case you want to learn Lambda functions, method references and stream API in more details,
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:09,000 --> 00:01:12,000
|
| 67 |
+
feel free to refer to that section.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:12,000 --> 00:01:15,000
|
| 71 |
+
In this lesson we will also review some examples.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:15,000 --> 00:01:23,000
|
| 75 |
+
But as I said, if you need even more details, feel free to check separate section of the course dedicated
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:23,000 --> 00:01:24,000
|
| 79 |
+
to these topics.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:24,000 --> 00:01:31,000
|
| 83 |
+
Because Java version eight was revolutionary back then and features introduced in Java eight were huge.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:32,000 --> 00:01:37,000
|
| 87 |
+
That's why I created separate lessons for those topics and even separate sections.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:38,000 --> 00:01:41,000
|
| 91 |
+
Also, we are going to learn optional class in my Java course.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:41,000 --> 00:01:44,000
|
| 95 |
+
We already had a separate lesson for that one two.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:44,000 --> 00:01:48,000
|
| 99 |
+
But today we will make a summary and highlight the most important points.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:48,000 --> 00:01:50,000
|
| 103 |
+
Repeating annotations.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:50,000 --> 00:01:52,000
|
| 107 |
+
That is something new for you.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:52,000 --> 00:01:55,000
|
| 111 |
+
Because I didn't have opportunity to stop on this topic before.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:55,000 --> 00:02:00,000
|
| 115 |
+
You see, not all topics require separate lessons because they are not so huge.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:00,000 --> 00:02:09,000
|
| 119 |
+
That's why we will use some topics in scope of other lessons and new data time API in my course Java
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:09,000 --> 00:02:15,000
|
| 123 |
+
from zero to first job, I created separate section with multiple lessons about date and time in JDK.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:15,000 --> 00:02:18,000
|
| 127 |
+
But today we are going to make a summary.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:18,000 --> 00:02:24,000
|
| 131 |
+
And at the end of the lesson, we are going to learn two things that were marked as deprecated in Java
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:24,000 --> 00:02:25,000
|
| 135 |
+
version eight.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:25,000 --> 00:02:28,000
|
| 139 |
+
I am talking about the extension mechanism.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:28,000 --> 00:02:35,000
|
| 143 |
+
Java ext dirs property and rarely used garbage collectors combinations.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:35,000 --> 00:02:38,000
|
| 147 |
+
So let's start our lesson.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:39,000 --> 00:02:45,000
|
| 151 |
+
As I already mentioned, today we are going to have a lesson full of practical examples and exercises.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:45,000 --> 00:02:51,000
|
| 155 |
+
So let me just start screen sharing and review with the examples that I prepared for you.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:51,000 --> 00:02:57,000
|
| 159 |
+
I prepared examples before the lesson in order to not spend your time during the video lesson, you
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:57,000 --> 00:03:00,000
|
| 163 |
+
sitting and waiting while I finish typing code.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:00,000 --> 00:03:04,000
|
| 167 |
+
And also I wanted to bring more structural approach into this lesson.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:05,000 --> 00:03:10,000
|
| 171 |
+
In attachments to the lesson, you can find the reference to the source code examples shared in the
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:10,000 --> 00:03:18,000
|
| 175 |
+
video, exploring the source code on your personal computer, changing it, playing with it will help
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:18,000 --> 00:03:24,000
|
| 179 |
+
you to understand the code better, so feel free to copy examples and understand them.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:25,000 --> 00:03:29,000
|
| 183 |
+
We are going to review this example line by line.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:29,000 --> 00:03:30,000
|
| 187 |
+
Always remember that.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:30,000 --> 00:03:35,000
|
| 191 |
+
I encourage you to ask questions below the video in case something is not clear.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:35,000 --> 00:03:40,000
|
| 195 |
+
You don't have to write in reviews at course was unclear and lessons are bad.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:40,000 --> 00:03:44,000
|
| 199 |
+
Just post your questions below the video and I will be happy to answer.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:45,000 --> 00:03:51,000
|
| 203 |
+
I check all questions on regular basis and make sure that all questions are properly answered.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:52,000 --> 00:03:57,000
|
| 207 |
+
I will run this program and together we will explore console output with the source code.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:58,000 --> 00:04:02,000
|
| 211 |
+
And I want to start with interface, default and static methods.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:02,000 --> 00:04:09,000
|
| 215 |
+
In Java, starting from version eight, interfaces can contain default and static methods, providing
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:09,000 --> 00:04:14,000
|
| 219 |
+
a new way to evolve interfaces without breaking existing implementations.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:15,000 --> 00:04:22,000
|
| 223 |
+
These methods offer a means to introduce new functionality to interfaces in a backward compatible manner.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:23,000 --> 00:04:25,000
|
| 227 |
+
A default method is a method in an interface.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:25,000 --> 00:04:28,000
|
| 231 |
+
It provides a default implementation.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:28,000 --> 00:04:36,000
|
| 235 |
+
It allows an interface to have massive implementations without forcing the implementing classes to provide
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:36,000 --> 00:04:38,000
|
| 239 |
+
their own implementation.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:38,000 --> 00:04:42,000
|
| 243 |
+
Default methods are declared using the default keyword.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:43,000 --> 00:04:50,000
|
| 247 |
+
In this example, I declared my interface in the same file, just to keep all examples grouped together
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:50,000 --> 00:04:51,000
|
| 251 |
+
in one file.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:51,000 --> 00:04:59,000
|
| 255 |
+
As you can see, my interface has regular abstract method without method body has default methods that
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:59,000 --> 00:05:06,000
|
| 259 |
+
contains body and that has default keyword and static method that contains method, body and static
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:06,000 --> 00:05:07,000
|
| 263 |
+
keyword.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:08,000 --> 00:05:12,000
|
| 267 |
+
I have class that is called my class and it implements my interface.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:12,000 --> 00:05:18,000
|
| 271 |
+
And usually we have to give implementation to all abstract masses in class, right?
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:18,000 --> 00:05:25,000
|
| 275 |
+
We need to do this to define specific behavior and to be able to create instances of this class.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:25,000 --> 00:05:30,000
|
| 279 |
+
That's why I implemented only regular method and that's it.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:30,000 --> 00:05:35,000
|
| 283 |
+
You don't need to give implementation neither to default nor to static methods.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:36,000 --> 00:05:43,000
|
| 287 |
+
In main method you can see how I create instance of type my class and I invoke regular method and default
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:43,000 --> 00:05:46,000
|
| 291 |
+
method and pay attention to the console output.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:47,000 --> 00:05:52,000
|
| 295 |
+
Basically, the default method prints text that we defined in the interface.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:52,000 --> 00:05:57,000
|
| 299 |
+
That means that you don't need to force all classes that implements your interface.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:57,000 --> 00:06:00,000
|
| 303 |
+
Implement behavior for default method.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:01,000 --> 00:06:04,000
|
| 307 |
+
Instead, you can suggest the default behavior for method.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:04,000 --> 00:06:06,000
|
| 311 |
+
And that's it.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:06,000 --> 00:06:08,000
|
| 315 |
+
That's what default methods are about.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:09,000 --> 00:06:11,000
|
| 319 |
+
With static methods, everything is simple.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:11,000 --> 00:06:16,000
|
| 323 |
+
Static methods in interface are similar to static methods in classes.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:16,000 --> 00:06:22,000
|
| 327 |
+
They are associated with the interface and can be invoked using the interface name.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:22,000 --> 00:06:28,000
|
| 331 |
+
Static methods are defined using the static keyword and the same as all static methods.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:28,000 --> 00:06:36,000
|
| 335 |
+
You can't override behavior of static methods, so when to use what, when to use default masses and
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:36,000 --> 00:06:38,000
|
| 339 |
+
when to use static methods.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:38,000 --> 00:06:43,000
|
| 343 |
+
I believe that you already know the answer, so let me just make a summary.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:44,000 --> 00:06:50,000
|
| 347 |
+
Default methods are useful for evolving interfaces without breaking existing implementations.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:50,000 --> 00:06:57,000
|
| 351 |
+
For example, adding new methods to existing Java collections interfaces without forcing developers
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:57,000 --> 00:06:59,000
|
| 355 |
+
to update their implementations.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:00,000 --> 00:07:06,000
|
| 359 |
+
Static masses handy for providing utility masses related to the interface.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:06,000 --> 00:07:11,000
|
| 363 |
+
For instance, helper masses for processing data specific to the interface.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:11,000 --> 00:07:14,000
|
| 367 |
+
Use this toolset wisely.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:14,000 --> 00:07:20,000
|
| 371 |
+
Also, feel free to refer to the lesson about interfaces in my course Java from zero to First Job.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:20,000 --> 00:07:26,000
|
| 375 |
+
In that lesson, I reviewed different combinations of default methods and showed examples of diamond
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:26,000 --> 00:07:33,000
|
| 379 |
+
problem because technically speaking, class may implement multiple interfaces, right?
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:33,000 --> 00:07:40,000
|
| 383 |
+
And multiple interfaces theoretically may declare masses with the same signature, and this will cause
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:40,000 --> 00:07:41,000
|
| 387 |
+
compilation error.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:42,000 --> 00:07:47,000
|
| 391 |
+
This is called problem of a diamond or simply diamond problem.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:47,000 --> 00:07:55,000
|
| 395 |
+
Talents at Java don't know which default implementation of the method from which interface to select
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:55,000 --> 00:07:56,000
|
| 399 |
+
during the runtime.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:57,000 --> 00:08:04,000
|
| 403 |
+
Okay, let's move on and talk about such feature as functional interface that was also introduced in
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:04,000 --> 00:08:06,000
|
| 407 |
+
Java version eight.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:06,000 --> 00:08:14,000
|
| 411 |
+
In Java eight, the concept of functional interfaces was introduced to support the new features like
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:14,000 --> 00:08:17,000
|
| 415 |
+
lambda expressions and method references.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:17,000 --> 00:08:19,000
|
| 419 |
+
We'll review them in a minute too.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:19,000 --> 00:08:27,000
|
| 423 |
+
A functional interface is an interface that contains exactly one abstract method known as a functional
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:27,000 --> 00:08:28,000
|
| 427 |
+
method.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:28,000 --> 00:08:36,000
|
| 431 |
+
Functional interfaces can have multiple default or static methods, but they must have only one abstract
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:36,000 --> 00:08:39,000
|
| 435 |
+
method to qualify as a functional interface.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:40,000 --> 00:08:46,000
|
| 439 |
+
So the interface with name my interface that we have just reviewed in scope of previous example is a
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:46,000 --> 00:08:48,000
|
| 443 |
+
functional interface.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:48,000 --> 00:08:55,000
|
| 447 |
+
The functional interface annotation can be used to ensure that an interface is functional interface.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:56,000 --> 00:08:58,000
|
| 451 |
+
While the annotation is optional.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:58,000 --> 00:09:05,000
|
| 455 |
+
It's good practice to use it to clearly indicate the intention of creating a functional interface,
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:05,000 --> 00:09:11,000
|
| 459 |
+
and in case there will be two abstract methods, or somebody would decide to add more abstract methods
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:11,000 --> 00:09:17,000
|
| 463 |
+
to the interface, there will be compilation error reminding you that this is functional interface,
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:17,000 --> 00:09:20,000
|
| 467 |
+
and you should have only one abstract method.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:21,000 --> 00:09:25,000
|
| 471 |
+
In main method you can find example of usage of functional interface.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:26,000 --> 00:09:30,000
|
| 475 |
+
Usually, functional interfaces are defined in order to flag that.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:30,000 --> 00:09:33,000
|
| 479 |
+
You can describe this type with lambda expression.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:34,000 --> 00:09:43,000
|
| 483 |
+
In this case it is anonymous method without name and without parameters defined that just prints text
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:43,000 --> 00:09:47,000
|
| 487 |
+
to console and basically to create instance of my interface.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:47,000 --> 00:09:51,000
|
| 491 |
+
You just need to provide implementation of one abstract method, right?
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:52,000 --> 00:09:55,000
|
| 495 |
+
That would be enough for Java to create object of this type.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:56,000 --> 00:10:02,000
|
| 499 |
+
That's why providing anonymous function is enough for Java to create object of my interface type.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:03,000 --> 00:10:06,000
|
| 503 |
+
Let's learn what lambda expressions are in details.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:07,000 --> 00:10:13,000
|
| 507 |
+
Lambda expressions introduced in Java eight, provides a concise way to express instances of single
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:13,000 --> 00:10:15,000
|
| 511 |
+
method interfaces.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:15,000 --> 00:10:17,000
|
| 515 |
+
Functional interfaces.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:17,000 --> 00:10:24,000
|
| 519 |
+
They enhance the readability and maintainability of Java code by allowing the expression of instances
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:24,000 --> 00:10:27,000
|
| 523 |
+
of single method interfaces more briefly.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:28,000 --> 00:10:31,000
|
| 527 |
+
A lambda expression consists of three main components.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:32,000 --> 00:10:37,000
|
| 531 |
+
Parameters similar to method parameters, but without explicit types.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:37,000 --> 00:10:43,000
|
| 535 |
+
If a lambda takes no parameters, you use an empty set of parentheses.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:43,000 --> 00:10:48,000
|
| 539 |
+
If it takes multiple parameters, you separate them with commas.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:48,000 --> 00:10:54,000
|
| 543 |
+
If you want, you can specify types of parameters vividly, but it is not mandatory.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:56,000 --> 00:11:03,000
|
| 547 |
+
The next component is arrow token, known as the lambda operator or arrow token.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:03,000 --> 00:11:08,000
|
| 551 |
+
It separates the parameter list from the body of the lambda expression.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:08,000 --> 00:11:14,000
|
| 555 |
+
It signifies that the parameters are being used to produce the result defined by the lambda.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:15,000 --> 00:11:17,000
|
| 559 |
+
The third component body.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:17,000 --> 00:11:23,000
|
| 563 |
+
It contains the code that specifies what the lambda expression does for a single expression.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:23,000 --> 00:11:27,000
|
| 567 |
+
The body can be just that expression for multiple statements.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:27,000 --> 00:11:31,000
|
| 571 |
+
The body is enclosed in curly braces.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:31,000 --> 00:11:36,000
|
| 575 |
+
For example, comparator is a functional interface.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:36,000 --> 00:11:38,000
|
| 579 |
+
It has just one abstract mass it.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:38,000 --> 00:11:44,000
|
| 583 |
+
Compare that we need to implement in order to be able to create instances of comparator type.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:45,000 --> 00:11:50,000
|
| 587 |
+
Here is an example of how a comparator implementation looked before Java eight.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:50,000 --> 00:11:55,000
|
| 591 |
+
Basically, you described anonymous class where you provided implementation to the method.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:56,000 --> 00:11:58,000
|
| 595 |
+
This is just a sorting example.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:59,000 --> 00:12:04,000
|
| 599 |
+
And here is an example of how we can take advantage of lambda expressions.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:04,000 --> 00:12:09,000
|
| 603 |
+
Basically we just provide an implementation of compare method here.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:09,000 --> 00:12:11,000
|
| 607 |
+
Here are two parameters.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:11,000 --> 00:12:16,000
|
| 611 |
+
And compiler is smart enough to understand that these are strings.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:16,000 --> 00:12:18,000
|
| 615 |
+
And here is method body.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:19,000 --> 00:12:25,000
|
| 619 |
+
Taking into account it takes just one line I don't need to use curly brackets.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:25,000 --> 00:12:29,000
|
| 623 |
+
And compiler is also smart enough to understand that.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:29,000 --> 00:12:35,000
|
| 627 |
+
Here is return statement because it knows that comparator should be here.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:35,000 --> 00:12:42,000
|
| 631 |
+
And in case lambda expressions matches requirements of abstract method, compiler is happy and this
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:42,000 --> 00:12:45,000
|
| 635 |
+
implementation will be used during the runtime.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:46,000 --> 00:12:52,000
|
| 639 |
+
In case you have any questions, please do not hesitate to post your questions below the video and I
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:52,000 --> 00:12:53,000
|
| 643 |
+
will be happy to answer.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:54,000 --> 00:12:58,000
|
| 647 |
+
There is another charm that was introduced starting from Java eight.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:58,000 --> 00:13:01,000
|
| 651 |
+
It is called effectively final variables.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:01,000 --> 00:13:03,000
|
| 655 |
+
Let's learn what are they about?
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:04,000 --> 00:13:11,000
|
| 659 |
+
In Java, a variable is considered effectively final if its value doesn't change after it is assigned.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:11,000 --> 00:13:17,000
|
| 663 |
+
This concept becomes relevant with the introduction of lambda expressions in Java eight.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:17,000 --> 00:13:24,000
|
| 667 |
+
Lambda expressions in Java eight have a restriction that they can only capture variables that are effectively
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:24,000 --> 00:13:24,000
|
| 671 |
+
final.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:25,000 --> 00:13:30,000
|
| 675 |
+
In a lambda expression, you can reference variables from the surrounding scope.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:30,000 --> 00:13:35,000
|
| 679 |
+
However, these variables must be effectively final and effectively.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:35,000 --> 00:13:40,000
|
| 683 |
+
Final variable is a variable whose value doesn't change after it is initially assigned.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:41,000 --> 00:13:49,000
|
| 687 |
+
In this example, regular variable is a regular variable while effectively final variable is effectively
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:49,000 --> 00:13:49,000
|
| 691 |
+
final.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:50,000 --> 00:13:57,000
|
| 695 |
+
If you try to modify the regular variable after it is used in the lambda expression, you will get a
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:57,000 --> 00:13:59,000
|
| 699 |
+
compilation error.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:59,000 --> 00:14:05,000
|
| 703 |
+
This restriction is in place to ensure that lambda expressions can safely capture variables from the
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:05,000 --> 00:14:09,000
|
| 707 |
+
enclosing scope, without unexpected changes.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:09,000 --> 00:14:11,000
|
| 711 |
+
What are use cases?
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:11,000 --> 00:14:19,000
|
| 715 |
+
This effectively final rule ensures that lambda expressions behave predictably and don't introduce side
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:19,000 --> 00:14:22,000
|
| 719 |
+
effects by modifying variables from the enclosing scope.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:22,000 --> 00:14:29,000
|
| 723 |
+
It promotes safer and more readable code by avoiding accidental modifications of captured variables.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:29,000 --> 00:14:36,000
|
| 727 |
+
Keep in mind that starting from Java eight, the compiler is smart enough to recognize effectively final
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:36,000 --> 00:14:40,000
|
| 731 |
+
variables, and you don't have to explicitly declare them as such.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:41,000 --> 00:14:47,000
|
| 735 |
+
If a variable is effectively final, the compiler will treat it accordingly, allowing you to use it
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:47,000 --> 00:14:49,000
|
| 739 |
+
in lambda expressions without any issues.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:50,000 --> 00:14:54,000
|
| 743 |
+
What is the difference between final variables and effectively final variables?
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:55,000 --> 00:15:01,000
|
| 747 |
+
An effectively final variable is a concept that comes into play specifically in the context of lambda
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:01,000 --> 00:15:03,000
|
| 751 |
+
expressions introduced in Java eight.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:04,000 --> 00:15:10,000
|
| 755 |
+
According to the language specification, a variable referenced in a lambda expression must be effectively
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:10,000 --> 00:15:17,000
|
| 759 |
+
final, meaning its value doesn't change after it is assigned and it shouldn't necessarily have final
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:17,000 --> 00:15:23,000
|
| 763 |
+
modifier, and final variable is called so when it has final modifier.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:23,000 --> 00:15:25,000
|
| 767 |
+
That's the difference.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:26,000 --> 00:15:32,000
|
| 771 |
+
This next feature that was also introduced in Java eight, and that I want to review with you is method
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:32,000 --> 00:15:33,000
|
| 775 |
+
reference.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:33,000 --> 00:15:40,000
|
| 779 |
+
Method references in Java provide a shorthand notation for expressing lambda expressions that directly
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:40,000 --> 00:15:42,000
|
| 783 |
+
invoke a method or constructor.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:42,000 --> 00:15:49,000
|
| 787 |
+
They make the code more concise and readable, especially when the lambda expression merely calls an
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:49,000 --> 00:15:50,000
|
| 791 |
+
existing method.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:51,000 --> 00:15:57,000
|
| 795 |
+
Method references are particularly useful when working with functional interfaces, allowing you to
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:57,000 --> 00:16:00,000
|
| 799 |
+
replace lambda expressions with a reference to an existing method.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:01,000 --> 00:16:04,000
|
| 803 |
+
There are four main types of method references.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:16:04,000 --> 00:16:10,000
|
| 807 |
+
They are reference to a static method and here you can see an example.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:16:11,000 --> 00:16:14,000
|
| 811 |
+
Reference to an instance method of a particular object.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:16:14,000 --> 00:16:22,000
|
| 815 |
+
In this example, you can see how I put the reference to the println method of the out object from the
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:22,000 --> 00:16:23,000
|
| 819 |
+
system class.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:24,000 --> 00:16:29,000
|
| 823 |
+
Reference to an instance method of an arbitrary object of a particular type.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:29,000 --> 00:16:37,000
|
| 827 |
+
As you can see, this is reference not to a static method, but I use type name here instead of reference
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:37,000 --> 00:16:38,000
|
| 831 |
+
to a particular object.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:16:39,000 --> 00:16:46,000
|
| 835 |
+
In this example, this lambda expression and this method reference performs the same operation on each
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:46,000 --> 00:16:53,000
|
| 839 |
+
object, whereas this comparator will be used and describes the logic of string comparing.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:16:54,000 --> 00:17:01,000
|
| 843 |
+
Reference to a constructor in Java eight API, you would find cases when an interface requires you to
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:17:01,000 --> 00:17:07,000
|
| 847 |
+
provide some kind of supplier that knows how to create objects of the specific type.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:17:07,000 --> 00:17:12,000
|
| 851 |
+
In such cases, you can use method references like this.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:17:13,000 --> 00:17:15,000
|
| 855 |
+
I believe that syntax is clear.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:17:15,000 --> 00:17:20,000
|
| 859 |
+
In case you have any questions, post your questions below the video players.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:20,000 --> 00:17:25,000
|
| 863 |
+
The next feature of Java eight is that I would like to review with you is stream API.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:17:26,000 --> 00:17:32,000
|
| 867 |
+
The stream API introduced in Java eight, provides a powerful and expressive way to process and manipulate
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:17:32,000 --> 00:17:34,000
|
| 871 |
+
collections of data.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:34,000 --> 00:17:41,000
|
| 875 |
+
It allows developers to write functional style code to perform operations on collections, enabling
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:41,000 --> 00:17:44,000
|
| 879 |
+
concise and readable code for data processing.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:44,000 --> 00:17:47,000
|
| 883 |
+
Streams are not collections themselves.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:17:48,000 --> 00:17:54,000
|
| 887 |
+
Rather, they are a pipeline of data that can be processed in a functional programming paradigm.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:17:54,000 --> 00:18:01,000
|
| 891 |
+
Streams can be created from various sources such as collections, arrays, or input output channels.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:02,000 --> 00:18:05,000
|
| 895 |
+
For example, creating a stream from a list.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:06,000 --> 00:18:07,000
|
| 899 |
+
Intermediate operations.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:18:08,000 --> 00:18:12,000
|
| 903 |
+
Intermediate operations transform a stream into another stream.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:18:12,000 --> 00:18:18,000
|
| 907 |
+
They are lazy and do not execute until a terminal operation is invoked.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:18:18,000 --> 00:18:21,000
|
| 911 |
+
For example, such intermediate operations as.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:18:21,000 --> 00:18:23,000
|
| 915 |
+
Filter map.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:18:23,000 --> 00:18:23,000
|
| 919 |
+
Distinct.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:18:23,000 --> 00:18:24,000
|
| 923 |
+
Sorted.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:18:25,000 --> 00:18:33,000
|
| 927 |
+
Terminal operations produce a result or a side effect and terminate the stream after a terminal operation.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:18:33,000 --> 00:18:41,000
|
| 931 |
+
A stream cannot be reused, for example, for each collect reuse count.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:18:42,000 --> 00:18:44,000
|
| 935 |
+
Parallel streams.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:18:44,000 --> 00:18:49,000
|
| 939 |
+
Streams can be processed in parallel to take advantage of multi-core processors.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:18:50,000 --> 00:18:57,000
|
| 943 |
+
But be careful with this in multi-threading part of the course, I explained in details how multi-threading
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:57,000 --> 00:18:58,000
|
| 947 |
+
works in Java.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:58,000 --> 00:19:06,000
|
| 951 |
+
Be aware that on some amount of data, parallel processing can take longer than single thread processing
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:19:06,000 --> 00:19:12,000
|
| 955 |
+
because of additional efforts that are required to synchronize work of threads between each other.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:19:12,000 --> 00:19:17,000
|
| 959 |
+
You can use parallel processing with parallel stream.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:19:17,000 --> 00:19:24,000
|
| 963 |
+
In my example, you can see how I filtered strings based on the condition and turned all strings to
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:19:24,000 --> 00:19:25,000
|
| 967 |
+
uppercase.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:19:25,000 --> 00:19:32,000
|
| 971 |
+
In the next example, I used count terminal function to count amount of elements left after filtering.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:19:33,000 --> 00:19:39,000
|
| 975 |
+
Feel free to check Java Collections Framework section of the course where I explained a lot of others
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:19:39,000 --> 00:19:42,000
|
| 979 |
+
different examples of using stream API.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:19:43,000 --> 00:19:49,000
|
| 983 |
+
The next cool and useful feature that was also introduced in Java eight is optional.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:19:49,000 --> 00:19:56,000
|
| 987 |
+
In Java eight, the optional class was introduced as a container object that may or may not contain
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:56,000 --> 00:19:58,000
|
| 991 |
+
a non-null value.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:59,000 --> 00:20:07,000
|
| 995 |
+
It helps to handle situations where a method may or may not return a result, avoiding null checks and
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:20:07,000 --> 00:20:11,000
|
| 999 |
+
providing a more expressive way to represent the absence of a value.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:20:11,000 --> 00:20:17,000
|
| 1003 |
+
The optional class was introduced to address the issue of dealing with potentially null values, and
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:20:17,000 --> 00:20:23,000
|
| 1007 |
+
to reduce the occurrence of null pointer exceptions when it is recommended to use.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:20:23,000 --> 00:20:24,000
|
| 1011 |
+
Optional.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:20:24,000 --> 00:20:31,000
|
| 1015 |
+
Using optional helps prevent null pointer exceptions by explicitly indicating the absence of a value.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:20:32,000 --> 00:20:38,000
|
| 1019 |
+
Optional provides a more expressive way to handle no checks compared to traditional node checks.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:20:39,000 --> 00:20:44,000
|
| 1023 |
+
It supports functional programming principles by providing masses for handling values in a functional
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:20:44,000 --> 00:20:45,000
|
| 1027 |
+
manner.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:20:46,000 --> 00:20:52,000
|
| 1031 |
+
Basically optional, acts as a wrapper around value, and API is built to provide you with different
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:20:52,000 --> 00:20:56,000
|
| 1035 |
+
options and opportunities to handle potential new values.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:56,000 --> 00:20:57,000
|
| 1039 |
+
Processing as you wish.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:58,000 --> 00:21:01,000
|
| 1043 |
+
I prepared different examples for you.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:21:01,000 --> 00:21:05,000
|
| 1047 |
+
Here is an example of how to create optional from string.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:21:05,000 --> 00:21:12,000
|
| 1051 |
+
Then goes example of how you can check if value is present in optional, and how to extract the value
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:21:12,000 --> 00:21:19,000
|
| 1055 |
+
in case you want to return some default value in case of null inside optional, you can use or else
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:21:19,000 --> 00:21:20,000
|
| 1059 |
+
method.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:21:21,000 --> 00:21:25,000
|
| 1063 |
+
Here is an example of how you can initialize optional out of null value.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:21:26,000 --> 00:21:31,000
|
| 1067 |
+
Also, in case you want to provide a function that would extract the default value in case of.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:21:31,000 --> 00:21:34,000
|
| 1071 |
+
Now you can use or else get method.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:21:35,000 --> 00:21:42,000
|
| 1075 |
+
You can also apply function to value if it is present with map function, or perform some function if
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:21:42,000 --> 00:21:46,000
|
| 1079 |
+
value is present using if present method.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:21:47,000 --> 00:21:54,000
|
| 1083 |
+
You can sync that if present method is similar to map function, but they are different if present.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:21:54,000 --> 00:21:57,000
|
| 1087 |
+
Returns void map.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:21:57,000 --> 00:22:01,000
|
| 1091 |
+
Returns a new optional containing the result of the transformation.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:22:02,000 --> 00:22:07,000
|
| 1095 |
+
Use if present when you want to perform an action on the value if it exists.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:22:08,000 --> 00:22:12,000
|
| 1099 |
+
Use map when you want to transform the value if it exists.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:22:12,000 --> 00:22:14,000
|
| 1103 |
+
That's all regarding optional.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:22:15,000 --> 00:22:20,000
|
| 1107 |
+
Feel free to check separate lesson with dedicated only to optional plus.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:22:21,000 --> 00:22:25,000
|
| 1111 |
+
The next features that we are going to review is called repeated annotations.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:22:26,000 --> 00:22:32,000
|
| 1115 |
+
Java eight introduced the Repeating Annotations feature, which allows you to apply the same annotation
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:22:32,000 --> 00:22:35,000
|
| 1119 |
+
more than once to a declaration.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:22:35,000 --> 00:22:41,000
|
| 1123 |
+
Before Java eight, if you wanted to use an annotation multiple times, you had to create a container
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:22:41,000 --> 00:22:45,000
|
| 1127 |
+
annotation to hold multiple instances of the target annotation.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:22:46,000 --> 00:22:50,000
|
| 1131 |
+
Repeating annotations simplifies this process.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:22:50,000 --> 00:22:57,000
|
| 1135 |
+
To define a repeated annotation, you need to use the repeatable meta annotation along with an annotation
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:22:57,000 --> 00:23:02,000
|
| 1139 |
+
type that acts as a container for the repeated annotations.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:23:02,000 --> 00:23:06,000
|
| 1143 |
+
What are the benefits and use cases of using repeated annotations?
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:23:07,000 --> 00:23:13,000
|
| 1147 |
+
Repeating annotations provide a more concise syntax for applying the same annotation multiple times.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:23:14,000 --> 00:23:20,000
|
| 1151 |
+
The code becomes more readable and avoids the need for a separate container annotation.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:23:20,000 --> 00:23:26,000
|
| 1155 |
+
Repeating annotations are particularly useful in frameworks and libraries, where the same annotation
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:23:26,000 --> 00:23:29,000
|
| 1159 |
+
might be applied multiple times with different values.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:23:30,000 --> 00:23:36,000
|
| 1163 |
+
If you scroll the source code to the bottom, you will see examples of repeated annotation.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:23:36,000 --> 00:23:39,000
|
| 1167 |
+
In order to create repeated annotation.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:23:39,000 --> 00:23:44,000
|
| 1171 |
+
You first need to create annotations that can store an array of other annotations.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:23:44,000 --> 00:23:51,000
|
| 1175 |
+
And when you use repeatable annotation during the definition of the new annotation, you need to provide
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:23:51,000 --> 00:23:57,000
|
| 1179 |
+
it with the class that knows how to store an array of annotations of specific type.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:23:57,000 --> 00:24:03,000
|
| 1183 |
+
And in my class example, you can see how I used multiple annotations of the same type.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:24:03,000 --> 00:24:05,000
|
| 1187 |
+
Basically that's it.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:24:05,000 --> 00:24:10,000
|
| 1191 |
+
If you want to learn more about annotations, feel free to check my course Java from zero to First Job.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:24:11,000 --> 00:24:14,000
|
| 1195 |
+
There you will find separate lesson about annotations in Java.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:24:15,000 --> 00:24:20,000
|
| 1199 |
+
And in case you have any questions regarding repeating annotations, feel free to post your questions
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:24:20,000 --> 00:24:23,000
|
| 1203 |
+
below the video and I will be happy to answer you.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:24:24,000 --> 00:24:25,000
|
| 1207 |
+
At the meantime, let's continue.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:24:26,000 --> 00:24:31,000
|
| 1211 |
+
Huge achievement of Java eight is release of new data and time API.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:24:32,000 --> 00:24:39,000
|
| 1215 |
+
Java eight introduced a new date and Time API in the Java Time package to address the limitations and
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:24:39,000 --> 00:24:44,000
|
| 1219 |
+
shortcomings of the old Java.util.date and Java util calendar classes.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:24:45,000 --> 00:24:52,000
|
| 1223 |
+
The new API is more comprehensive, immutable, and provides better support for handling date and time
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:24:52,000 --> 00:24:53,000
|
| 1227 |
+
operations.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:24:53,000 --> 00:24:57,000
|
| 1231 |
+
The key classes in the new date and Time API include.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:24:57,000 --> 00:25:05,000
|
| 1235 |
+
Local date, local time, local date time, zoned date time, instant duration, and period.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:25:05,000 --> 00:25:10,000
|
| 1239 |
+
In this lesson, I don't have goal to review all API in details.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:25:10,000 --> 00:25:16,000
|
| 1243 |
+
There is a separate section in my course Java from zero to first job that is called date and time in
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:25:16,000 --> 00:25:17,000
|
| 1247 |
+
GCC.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:25:18,000 --> 00:25:25,000
|
| 1251 |
+
This section consists of multiple lessons where we learn API in details with all possible examples.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:25:25,000 --> 00:25:30,000
|
| 1255 |
+
That's why I wouldn't stop too much on this topic in scope of this lesson, because I have multiple
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:25:30,000 --> 00:25:33,000
|
| 1259 |
+
other lessons dedicated to this topic.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:25:33,000 --> 00:25:39,000
|
| 1263 |
+
But still, in the file with the source code of examples, you can find examples of different cases
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:25:39,000 --> 00:25:41,000
|
| 1267 |
+
and examples of different types.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:25:41,000 --> 00:25:45,000
|
| 1271 |
+
Namely, there are examples with local date.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:25:45,000 --> 00:25:47,000
|
| 1275 |
+
Local time.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:25:47,000 --> 00:25:47,000
|
| 1279 |
+
Local date.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:25:47,000 --> 00:25:49,000
|
| 1283 |
+
Time zone.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:25:49,000 --> 00:25:50,000
|
| 1287 |
+
Date time.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:25:50,000 --> 00:25:52,000
|
| 1291 |
+
Instant duration period.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:25:53,000 --> 00:25:56,000
|
| 1295 |
+
Take your time exploring these examples.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:25:56,000 --> 00:26:00,000
|
| 1299 |
+
In case you want to learn more, feel free to check the sections that I mentioned.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:26:00,000 --> 00:26:04,000
|
| 1303 |
+
And in case of any questions, post them below the video.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:26:04,000 --> 00:26:05,000
|
| 1307 |
+
Let's move on.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:26:06,000 --> 00:26:11,000
|
| 1311 |
+
But new Java version is not just about introduction of new things.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:26:12,000 --> 00:26:15,000
|
| 1315 |
+
It is also about marking some things as deprecated.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:26:16,000 --> 00:26:23,000
|
| 1319 |
+
Marking sinks as deprecated doesn't necessarily mean that these things will be removed from next JDK
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:26:23,000 --> 00:26:24,000
|
| 1323 |
+
version.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:26:25,000 --> 00:26:31,000
|
| 1327 |
+
The deprecation process typically involves marking an element as deprecated in one release, and then
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:26:31,000 --> 00:26:34,000
|
| 1331 |
+
remove it in in a subsequent release.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:26:35,000 --> 00:26:41,000
|
| 1335 |
+
This provides developers with the time to update their code and migrate to alternative solutions.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:26:42,000 --> 00:26:49,000
|
| 1339 |
+
Deprecation is often used when there are better alternatives available, and developers are encouraged
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:26:49,000 --> 00:26:51,000
|
| 1343 |
+
to use the newer options.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:26:52,000 --> 00:26:59,000
|
| 1347 |
+
In some cases, deprecation may be related to security concerns, and continued use of the deprecated
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:26:59,000 --> 00:27:04,000
|
| 1351 |
+
element may pose risks as APIs evolve.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:27:04,000 --> 00:27:11,000
|
| 1355 |
+
Certain elements may become outdated, and deprecation provides a clear path for developers to transition
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:27:11,000 --> 00:27:12,000
|
| 1359 |
+
to newer features.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:27:13,000 --> 00:27:20,000
|
| 1363 |
+
But in Java eight, some things were marked as deprecated and were already removed in Java version nine.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:27:20,000 --> 00:27:24,000
|
| 1367 |
+
So let's review things that were marked as deprecated in Java eight.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:27:25,000 --> 00:27:29,000
|
| 1371 |
+
Let's review the deprecation of extension mechanism.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:27:29,000 --> 00:27:36,000
|
| 1375 |
+
The extension mechanism in Java was a feature that allowed developers to extend the core functionality
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:27:36,000 --> 00:27:41,000
|
| 1379 |
+
of the Java platform by adding custom classes to the extension directories.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:27:41,000 --> 00:27:48,000
|
| 1383 |
+
These extension directories were specified by the Java ext system property, and typically contained
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:27:48,000 --> 00:27:56,000
|
| 1387 |
+
Jar files with classes that extended or replaced existing classes in the Java standard libraries.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:27:57,000 --> 00:28:05,000
|
| 1391 |
+
The Java ext year property was used to specify one or more directories containing extension libraries.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:28:05,000 --> 00:28:12,000
|
| 1395 |
+
When Java Virtual Machine started, it would look in these directories to find and load classes before
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:28:12,000 --> 00:28:14,000
|
| 1399 |
+
checking the standard classpath.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:28:14,000 --> 00:28:21,000
|
| 1403 |
+
This allowed developers to add or replace classes in the standard libraries without modifying the core
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:28:21,000 --> 00:28:23,000
|
| 1407 |
+
Java installation.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:28:23,000 --> 00:28:27,000
|
| 1411 |
+
However, the extension mechanism had several drawbacks and issues.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:28:28,000 --> 00:28:31,000
|
| 1415 |
+
Number one global namespace.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:28:31,000 --> 00:28:38,000
|
| 1419 |
+
All installed extensions shared the same global namespace, which could lead to naming conflicts.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:28:38,000 --> 00:28:46,000
|
| 1423 |
+
If multiple extensions defined classes with the same name, it could result in unpredictable behavior.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:28:47,000 --> 00:28:48,000
|
| 1427 |
+
Versioning issues.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:28:48,000 --> 00:28:55,000
|
| 1431 |
+
There was no clear versioning mechanism for extensions if different applications relied on different
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:28:55,000 --> 00:28:56,000
|
| 1435 |
+
versions of an extension.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:28:56,000 --> 00:28:58,000
|
| 1439 |
+
Conflicts could arise.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:28:59,000 --> 00:29:01,000
|
| 1443 |
+
Security concerns.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:29:01,000 --> 00:29:06,000
|
| 1447 |
+
Allowing applications to modify the core libraries raised security concerns.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:29:07,000 --> 00:29:14,000
|
| 1451 |
+
Malicious extensions could potentially compromise the stability and security of the Java Runtime environment.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:29:14,000 --> 00:29:16,000
|
| 1455 |
+
LastPass complexity.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:29:16,000 --> 00:29:23,000
|
| 1459 |
+
The extension mechanism added complexity to the classpath resolution process, making it harder to manage
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:29:23,000 --> 00:29:26,000
|
| 1463 |
+
dependencies and troubleshoot issues.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:29:27,000 --> 00:29:33,000
|
| 1467 |
+
Due to these issues and the evolving security requirements, the extension mechanism was deprecated
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:29:33,000 --> 00:29:34,000
|
| 1471 |
+
in Java eight.
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:29:35,000 --> 00:29:41,000
|
| 1475 |
+
Deprecated means that the feature is still available, but it is advised against using it because it
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:29:41,000 --> 00:29:44,000
|
| 1479 |
+
may be removed in future versions.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:29:44,000 --> 00:29:51,000
|
| 1483 |
+
As an alternative, developers are encouraged to use other mechanisms for extended functionality, such
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:29:51,000 --> 00:29:53,000
|
| 1487 |
+
as using standard classpath entries.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:29:53,000 --> 00:29:59,000
|
| 1491 |
+
Build tools like Maven or Gradle for managing dependencies and modularization.
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:29:59,000 --> 00:30:04,000
|
| 1495 |
+
Introduced in Java nine with the Java Platform Module system.
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:30:04,000 --> 00:30:11,000
|
| 1499 |
+
So the deprecation of the extension mechanism was a step towards addressing naming conflicts, versioning
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:30:11,000 --> 00:30:18,000
|
| 1503 |
+
issues and security concerns, while encouraging better practices for managing dependencies and modularization
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:30:18,000 --> 00:30:20,000
|
| 1507 |
+
in Java applications.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:30:21,000 --> 00:30:27,000
|
| 1511 |
+
Another thing that was deprecated are some rarely used garbage collection combinations.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:30:27,000 --> 00:30:35,000
|
| 1515 |
+
The motivation behind deprecation lies in addressing the high maintenance costs associated with maintaining
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:30:35,000 --> 00:30:38,000
|
| 1519 |
+
deprecated garbage collector combinations.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:30:38,000 --> 00:30:45,000
|
| 1523 |
+
By removing these combinations, the hotspot garbage collector code can be simplified, resulting in
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:30:45,000 --> 00:30:52,000
|
| 1527 |
+
a reduction of bugs and facilitating faster development of remaining garbage collector combinations.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:30:52,000 --> 00:31:00,000
|
| 1531 |
+
The core of this deprecation is the removal of flags that control deprecated garbage collector combinations
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:31:00,000 --> 00:31:04,000
|
| 1535 |
+
and concurrent mark sweep foreground collector flags.
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:31:05,000 --> 00:31:08,000
|
| 1539 |
+
This removal means no deprecation messages will be printed.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:31:09,000 --> 00:31:13,000
|
| 1543 |
+
Instead, the JVM will not start if these deprecated flags are used.
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:31:14,000 --> 00:31:20,000
|
| 1547 |
+
This initiative will also lead to the removal of that code from the garbage collector code base.
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:31:20,000 --> 00:31:25,000
|
| 1551 |
+
Once the slide, you can find deprecated garbage collector combinations.
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:31:25,000 --> 00:31:32,000
|
| 1555 |
+
There is a risk that users need to update JVM startup command lines if they were using the removed flags.
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:31:32,000 --> 00:31:38,000
|
| 1559 |
+
However, the assumption is that users will benefit from migrating to more modern garbage collector
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:31:38,000 --> 00:31:40,000
|
| 1563 |
+
tuning options.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:31:40,000 --> 00:31:48,000
|
| 1567 |
+
The benefit of this deprecation includes a cleaner code base, reduced bugs, and an accelerated development
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:31:48,000 --> 00:31:48,000
|
| 1571 |
+
pace.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:31:49,000 --> 00:31:58,000
|
| 1575 |
+
Users transitioning from JDK eight to JDK nine should be aware of these deprecations, so it is recommended
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:31:58,000 --> 00:32:03,000
|
| 1579 |
+
embracing more modern garbage collector tuning options for optimal performance.
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:32:04,000 --> 00:32:06,000
|
| 1583 |
+
That's all regarding Java eight updates.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:32:06,000 --> 00:32:09,000
|
| 1587 |
+
I believe we need a great review.
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:32:09,000 --> 00:32:12,000
|
| 1591 |
+
Let's recap what we have learned in this lesson.
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:32:13,000 --> 00:32:21,000
|
| 1595 |
+
Java eight is a revolutionary update for Java, which updated Java significantly and increased its popularity
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:32:21,000 --> 00:32:23,000
|
| 1599 |
+
among modern programming languages.
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:32:24,000 --> 00:32:31,000
|
| 1603 |
+
We learned all new features that were released in Java version eight, namely interface, default and
|
| 1604 |
+
|
| 1605 |
+
402
|
| 1606 |
+
00:32:31,000 --> 00:32:37,000
|
| 1607 |
+
static methods, functional interfaces, Lambda expressions, message references.
|
| 1608 |
+
|
| 1609 |
+
403
|
| 1610 |
+
00:32:37,000 --> 00:32:43,000
|
| 1611 |
+
Effectively final variables stream API optional class repeating annotations.
|
| 1612 |
+
|
| 1613 |
+
404
|
| 1614 |
+
00:32:43,000 --> 00:32:45,000
|
| 1615 |
+
New data time API.
|
| 1616 |
+
|
| 1617 |
+
405
|
| 1618 |
+
00:32:45,000 --> 00:32:51,000
|
| 1619 |
+
Besides learning what was new in Java eight, we learned also what was marked as deprecated in Java
|
| 1620 |
+
|
| 1621 |
+
406
|
| 1622 |
+
00:32:51,000 --> 00:32:52,000
|
| 1623 |
+
eight.
|
| 1624 |
+
|
| 1625 |
+
407
|
| 1626 |
+
00:32:52,000 --> 00:32:59,000
|
| 1627 |
+
We learned about deprecation of the extension mechanism and deprecation of rarely used garbage collectors
|
| 1628 |
+
|
| 1629 |
+
408
|
| 1630 |
+
00:32:59,000 --> 00:33:00,000
|
| 1631 |
+
combinations.
|
| 1632 |
+
|
| 1633 |
+
409
|
| 1634 |
+
00:33:01,000 --> 00:33:03,000
|
| 1635 |
+
So that's it for this lesson.
|
| 1636 |
+
|
| 1637 |
+
410
|
| 1638 |
+
00:33:03,000 --> 00:33:05,000
|
| 1639 |
+
Thanks a lot for your attention.
|
| 1640 |
+
|
| 1641 |
+
411
|
| 1642 |
+
00:33:05,000 --> 00:33:08,000
|
| 1643 |
+
Have a great day and see you in the next lesson.
|
| 1644 |
+
|
44 - Java New Versions/001 Source-code-example-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/commit/040f22477c4b9d4d33c2be9d5a385821c6b866e6
|
44 - Java New Versions/002 Java 9 Stream API Updates, Multi-Resolution Image, Stack-Walking API, etc_en.srt
ADDED
|
@@ -0,0 +1,960 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello dear students, in this lesson we are going to learn features and updates in Java version nine.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:12,000 --> 00:00:19,000
|
| 7 |
+
Today we'll dive into language enhancements and API updates, discovering tools that simplify development
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:19,000 --> 00:00:21,000
|
| 11 |
+
and make your code more efficient.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:22,000 --> 00:00:26,000
|
| 15 |
+
Java nine introduces game changing improvements to the language.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:26,000 --> 00:00:32,000
|
| 19 |
+
We'll explore the flow API, empowering developers with reactive stream capabilities.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:32,000 --> 00:00:40,000
|
| 23 |
+
The Java Platform Module system revolutionized project organization and the collection factory methods
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:40,000 --> 00:00:45,000
|
| 27 |
+
that offer concise ways to create lists, sets, and maps.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:45,000 --> 00:00:53,000
|
| 31 |
+
Stream API enhancements, Multi-resolution image handling, and the Stack Walking API provide a comprehensive
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:53,000 --> 00:00:56,000
|
| 35 |
+
look at Java's evolving capabilities.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:56,000 --> 00:00:59,000
|
| 39 |
+
And also we'll review a lot of other features.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:00,000 --> 00:01:03,000
|
| 43 |
+
Our journey doesn't stop at language features.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:03,000 --> 00:01:05,000
|
| 47 |
+
We'll learn the process API updates.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:05,000 --> 00:01:12,000
|
| 51 |
+
Gaining in-depth insights into process management, the Completablefuture API introduces new methods
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:12,000 --> 00:01:14,000
|
| 55 |
+
for asynchronous operations.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:14,000 --> 00:01:20,000
|
| 59 |
+
We'll learn such tools as Jlink that provide practical solutions for creating custom jewelry, images,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:20,000 --> 00:01:22,000
|
| 63 |
+
and interactive Java commands.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:23,000 --> 00:01:28,000
|
| 67 |
+
I will explain you what the Jshell is and how you can use it during the development.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:28,000 --> 00:01:36,000
|
| 71 |
+
But besides new things, we'll also learn which things were marked as deprecated and which things were
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:36,000 --> 00:01:38,000
|
| 75 |
+
completely removed starting from Java nine.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:39,000 --> 00:01:46,000
|
| 79 |
+
I will highlight changes like the applet API deprecation, Cms's garbage collector removal, and the
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:46,000 --> 00:01:48,000
|
| 83 |
+
farewell to Java Web Start.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:48,000 --> 00:01:54,000
|
| 87 |
+
As you can see in the agenda, we have significantly more to learn in this lesson.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:55,000 --> 00:02:00,000
|
| 91 |
+
After this lesson, you are going to know literally everything about Java nine update and you will have
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:00,000 --> 00:02:03,000
|
| 95 |
+
enough knowledge to implement improvements on practice.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:03,000 --> 00:02:05,000
|
| 99 |
+
Let's start our lesson.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:06,000 --> 00:02:12,000
|
| 103 |
+
If you are a student of my course Java from zero to first job, then you are already aware of the fact
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:12,000 --> 00:02:16,000
|
| 107 |
+
that we learned some of the Java nine features before.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:16,000 --> 00:02:22,000
|
| 111 |
+
There are some bigger topics that may require separate lessons, and it would be hard to cover them
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:22,000 --> 00:02:26,000
|
| 115 |
+
together with other topics because we need more time to learn them.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:27,000 --> 00:02:34,000
|
| 119 |
+
Namely, we already had a lesson about flow API and reactive programming in Java, so feel free to find
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:34,000 --> 00:02:37,000
|
| 123 |
+
the full lesson about flow API in my course.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:37,000 --> 00:02:39,000
|
| 127 |
+
Java from zero to First job.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:40,000 --> 00:02:43,000
|
| 131 |
+
I will just briefly remind you what flow API is about.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:43,000 --> 00:02:49,000
|
| 135 |
+
The Java Flow API is a set of programming interfaces introduced in Java nine to simplify the development
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:49,000 --> 00:02:52,000
|
| 139 |
+
of reactive and asynchronous programming.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:52,000 --> 00:02:58,000
|
| 143 |
+
It provides a framework for handling streams of data in a non-blocking manner, allowing developers
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:58,000 --> 00:03:02,000
|
| 147 |
+
to write more scalable and responsive applications.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:02,000 --> 00:03:10,000
|
| 151 |
+
The flow API includes components such as publishers, subscribers, and processors which enable the
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:10,000 --> 00:03:12,000
|
| 155 |
+
implementation of reactive streams.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:12,000 --> 00:03:18,000
|
| 159 |
+
This facilitates the communication and coordination between different parts of a program, making it
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:18,000 --> 00:03:23,000
|
| 163 |
+
easier to handle asynchronous events and manage data flow efficiently.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:23,000 --> 00:03:30,000
|
| 167 |
+
Another topic that we already discussed and learned in a separate lesson is Java Platform Module System.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:30,000 --> 00:03:37,000
|
| 171 |
+
In my course Java from zero to first job, we have separate sections that is called Java Platform Module
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:37,000 --> 00:03:40,000
|
| 175 |
+
System and that consists of multiple lessons.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:41,000 --> 00:03:47,000
|
| 179 |
+
In those lessons, we review examples of modular application in Java and how to migrate existing Java
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:47,000 --> 00:03:50,000
|
| 183 |
+
applications to modular applications.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:50,000 --> 00:03:53,000
|
| 187 |
+
Let me remind you what this feature is about.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:53,000 --> 00:04:00,000
|
| 191 |
+
The Java Platform Module System is a feature introduced in Java nine to enhance modularity in the Java
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:00,000 --> 00:04:02,000
|
| 195 |
+
Standard Edition platform.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:03,000 --> 00:04:09,000
|
| 199 |
+
It enables developers to organize code into modular components called modules, allowing for better
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:09,000 --> 00:04:14,000
|
| 203 |
+
encapsulation, reusability, and maintainability of Java applications.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:15,000 --> 00:04:21,000
|
| 207 |
+
With Java Platform Module system, developers can explicitly declare dependencies between modules,
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:21,000 --> 00:04:25,000
|
| 211 |
+
leading to a more efficient and scalable software architecture.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:25,000 --> 00:04:32,000
|
| 215 |
+
This modular approach helps in managing the complexity of large code bases, improves code organization,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:32,000 --> 00:04:39,000
|
| 219 |
+
and enhances the maintainability of Java applications by reducing dependencies and providing a clearer
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:39,000 --> 00:04:43,000
|
| 223 |
+
separation of concerns between different parts of the system.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:44,000 --> 00:04:50,000
|
| 227 |
+
But there are a lot of other smaller updates that I decided to group in one lesson and review them with
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:50,000 --> 00:04:56,000
|
| 231 |
+
you today, and we are going to learn them on practical examples, especially for you.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:56,000 --> 00:04:59,000
|
| 235 |
+
I prepared code examples with new features.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:59,000 --> 00:05:03,000
|
| 239 |
+
In this way it will be easier for you to understand new concepts.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:04,000 --> 00:05:08,000
|
| 243 |
+
As always, you can find source code attachments to the lesson.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:08,000 --> 00:05:15,000
|
| 247 |
+
Let me start screen sharing and we will review examples that I prepared for you and grouped examples
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:15,000 --> 00:05:17,000
|
| 251 |
+
under Java nine package.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:17,000 --> 00:05:20,000
|
| 255 |
+
Feel free to explore the source code examples.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:20,000 --> 00:05:25,000
|
| 259 |
+
We are going to review each feature one by one in case you would have any questions.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:25,000 --> 00:05:30,000
|
| 263 |
+
Post your questions below the video and I will be happy to answer those.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:30,000 --> 00:05:33,000
|
| 267 |
+
I opened the file that is called Java nine.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:34,000 --> 00:05:39,000
|
| 271 |
+
Let me run it in order to print all console output and explore it with you.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:39,000 --> 00:05:42,000
|
| 275 |
+
Reviewing the source code line by line.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:42,000 --> 00:05:47,000
|
| 279 |
+
Let's review new collection factory methods that were introduced in Java nine.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:48,000 --> 00:05:51,000
|
| 283 |
+
List of set of map of.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:52,000 --> 00:05:58,000
|
| 287 |
+
Java nine introduced several new features, and one notable addition is a collection factory methods.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:59,000 --> 00:06:05,000
|
| 291 |
+
These methods provide a concise way to create immutable instances of lists, set and map.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:05,000 --> 00:06:12,000
|
| 295 |
+
The collection factory methods introduced in Java nine, such as list of set off and map off, produce
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:12,000 --> 00:06:14,000
|
| 299 |
+
immutable collections.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:14,000 --> 00:06:21,000
|
| 303 |
+
Immutability means that the contents of the collection can't be changed after the collection is created.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:22,000 --> 00:06:26,000
|
| 307 |
+
Let's review examples for each list of methods.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:26,000 --> 00:06:32,000
|
| 311 |
+
List of method allows you to create an immutable list with a specified number of elements.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:33,000 --> 00:06:38,000
|
| 315 |
+
In the example, the list of method is used to create an immutable list of strings.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:38,000 --> 00:06:46,000
|
| 319 |
+
Once created, the list can be modified, providing a simple and safe way to work with constant data.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:47,000 --> 00:06:48,000
|
| 323 |
+
Set off mast.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:49,000 --> 00:06:55,000
|
| 327 |
+
The set off method is used to create an immutable set with a specified elements.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:55,000 --> 00:07:02,000
|
| 331 |
+
In the example, the set off method creates an immutable set of integers similar to lists.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:02,000 --> 00:07:07,000
|
| 335 |
+
Sets created with this method can't be modified after creation.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:08,000 --> 00:07:09,000
|
| 339 |
+
Map of Mashhad.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:09,000 --> 00:07:14,000
|
| 343 |
+
The map of Mashhad creates an immutable map with key value pairs.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:15,000 --> 00:07:21,000
|
| 347 |
+
In this example, the map of Mashhad is used to create an immutable map where names are associated with
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:21,000 --> 00:07:23,000
|
| 351 |
+
the corresponding ages.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:23,000 --> 00:07:29,000
|
| 355 |
+
Once created, the entries in the map can be added, removed or modified.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:29,000 --> 00:07:36,000
|
| 359 |
+
This collection factory methods in Java nine provide a convenient way to create small, immutable collections
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:36,000 --> 00:07:43,000
|
| 363 |
+
with a simple and readable syntax, promoting better code clarity and reducing the risk of accidental
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:43,000 --> 00:07:45,000
|
| 367 |
+
modifications.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:45,000 --> 00:07:51,000
|
| 371 |
+
But why immutable collections are needed and in which cases it is recommended to use them.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:51,000 --> 00:07:56,000
|
| 375 |
+
There are several reasons why these collections are designed to be immutable.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:56,000 --> 00:07:58,000
|
| 379 |
+
Thread safety.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:58,000 --> 00:08:05,000
|
| 383 |
+
Immutable collections are inherently thread safe since the contents can be modified after creation.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:05,000 --> 00:08:12,000
|
| 387 |
+
There is no need for locks or synchronization mechanism when accessing collection from multiple threads.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:13,000 --> 00:08:19,000
|
| 391 |
+
This simplifies concurrent programming and reduces the risk of race conditions.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:20,000 --> 00:08:21,000
|
| 395 |
+
Predictable behavior.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:21,000 --> 00:08:28,000
|
| 399 |
+
Immutability ensures that the state of the collection remains constant throughout its life cycle.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:28,000 --> 00:08:35,000
|
| 403 |
+
This predictability is beneficial for reasoning about code, making it easier to understand and maintain.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:35,000 --> 00:08:43,000
|
| 407 |
+
Developers can rely on the fact that once a collection is created, its contents will not change unexpectedly.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:44,000 --> 00:08:45,000
|
| 411 |
+
Security.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:45,000 --> 00:08:53,000
|
| 415 |
+
Immutable collections can enhance security by preventing unintended modifications in scenarios where
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:53,000 --> 00:08:54,000
|
| 419 |
+
constant data is required.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:54,000 --> 00:09:02,000
|
| 423 |
+
Using immutable collections helps safeguard against accidental changes or tampering with critical data
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:02,000 --> 00:09:03,000
|
| 427 |
+
structures.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:04,000 --> 00:09:05,000
|
| 431 |
+
Simplified code.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:05,000 --> 00:09:11,000
|
| 435 |
+
Immutable collections encourage a functional programming style, where operations on collections do
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:11,000 --> 00:09:18,000
|
| 439 |
+
not modify the original data, but instead create new instances with the desired changes.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:18,000 --> 00:09:25,000
|
| 443 |
+
This can lead to cleaner and more maintainable code as it reduces the risk of side effects.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:25,000 --> 00:09:27,000
|
| 447 |
+
Performance optimizations.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:28,000 --> 00:09:31,000
|
| 451 |
+
Immutability allows for certain performance optimizations.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:31,000 --> 00:09:38,000
|
| 455 |
+
For instance, implementations can share internal data structures between different instances of immutable
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:38,000 --> 00:09:41,000
|
| 459 |
+
collections when they have the same elements.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:42,000 --> 00:09:48,000
|
| 463 |
+
This sharing reduces memory overhead and can lead to more efficient use of resources.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:49,000 --> 00:09:50,000
|
| 467 |
+
API design.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:50,000 --> 00:09:54,000
|
| 471 |
+
Immutable collections provide a clear and consistent API.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:54,000 --> 00:10:01,000
|
| 475 |
+
Once created, developers can rely on the fact that the collection will not be altered unexpectedly.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:01,000 --> 00:10:07,000
|
| 479 |
+
This simplicity in design makes APIs more intuitive and less error prone.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:08,000 --> 00:10:09,000
|
| 483 |
+
Okay.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:09,000 --> 00:10:11,000
|
| 487 |
+
Let's continue and review the next feature.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:11,000 --> 00:10:13,000
|
| 491 |
+
Let's get back to our source code.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:13,000 --> 00:10:14,000
|
| 495 |
+
Examples.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:15,000 --> 00:10:22,000
|
| 499 |
+
Java nine introduced several enhancements to the stream API, including the tick while drop while of
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:22,000 --> 00:10:26,000
|
| 503 |
+
nullable, and improvements to the iterate method.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:26,000 --> 00:10:29,000
|
| 507 |
+
Let's explore each of these features with examples.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:30,000 --> 00:10:31,000
|
| 511 |
+
Take wild method.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:32,000 --> 00:10:38,000
|
| 515 |
+
The Take wild method allows you to take elements from a stream while a specified condition holds true.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:39,000 --> 00:10:44,000
|
| 519 |
+
It stops processing the stream once the condition becomes false.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:44,000 --> 00:10:50,000
|
| 523 |
+
In the example, the take while method is used to take elements from the stream, while the condition
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:50,000 --> 00:10:54,000
|
| 527 |
+
and less than four holds true.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:55,000 --> 00:11:02,000
|
| 531 |
+
Drop while massive, the drop while massive skips elements from a stream while a specified condition
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:02,000 --> 00:11:04,000
|
| 535 |
+
holds true.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:04,000 --> 00:11:09,000
|
| 539 |
+
Basically, this method is the opposite to the one that we reviewed.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:09,000 --> 00:11:13,000
|
| 543 |
+
It starts processing the stream once the condition becomes false.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:14,000 --> 00:11:21,000
|
| 547 |
+
Here the drop while method skips elements until the condition n less than four becomes false.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:22,000 --> 00:11:24,000
|
| 551 |
+
Of nullable masses.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:24,000 --> 00:11:32,000
|
| 555 |
+
The of nullable method allows you to create a stream with a single non-null element, or an empty stream
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:32,000 --> 00:11:34,000
|
| 559 |
+
if the provided element is null.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:34,000 --> 00:11:40,000
|
| 563 |
+
In this example, the of nullable mass, it creates a stream with the value 42.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:41,000 --> 00:11:46,000
|
| 567 |
+
It helps in reducing the need for explicit null checks before creating a stream.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:46,000 --> 00:11:53,000
|
| 571 |
+
Instead of checking if an object is null and then deciding whether to create a stream, you can use
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:53,000 --> 00:11:56,000
|
| 575 |
+
stream of nullable method directly.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:56,000 --> 00:12:04,000
|
| 579 |
+
When working with optional values, stream of nullable can be used to convert an optional into a stream.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:04,000 --> 00:12:11,000
|
| 583 |
+
When the stream contains either the value if present or is empty if the optional is empty.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:12,000 --> 00:12:14,000
|
| 587 |
+
Improved iterate method.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:15,000 --> 00:12:22,000
|
| 591 |
+
The iterate method has been enhanced to take a predicate, allowing you to iterate over elements while
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:22,000 --> 00:12:24,000
|
| 595 |
+
a condition holds true.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:24,000 --> 00:12:31,000
|
| 599 |
+
Here, the iterate method generates a stream starting from one and doubling the value until the condition
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:31,000 --> 00:12:35,000
|
| 603 |
+
and less than ten becomes false.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:35,000 --> 00:12:42,000
|
| 607 |
+
This enhancements in Java nine stream API provide more expressive ways to work with streams, allowing
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:42,000 --> 00:12:49,000
|
| 611 |
+
for concise and readable code when dealing with conditions and transformations of streaming data.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:50,000 --> 00:12:56,000
|
| 615 |
+
The next update in Java nine is that I want to review with you is Multi-resolution image API.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:56,000 --> 00:13:04,000
|
| 619 |
+
The Multi-resolution image interface in Java is like a smart image that knows how to pick the best version
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:04,000 --> 00:13:08,000
|
| 623 |
+
of itself based on different resolutions or sizes.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:09,000 --> 00:13:16,000
|
| 627 |
+
It's useful when you have various versions of an image tailored for different screen sizes or display
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:16,000 --> 00:13:17,000
|
| 631 |
+
resolutions.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:17,000 --> 00:13:18,000
|
| 635 |
+
Why it is needed.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:19,000 --> 00:13:25,000
|
| 639 |
+
When you have an application that runs on devices with different screen sizes or resolutions, using
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:25,000 --> 00:13:30,000
|
| 643 |
+
Multi-resolution image can help display the most suitable image version for each device.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:31,000 --> 00:13:37,000
|
| 647 |
+
This ensures that your application looks good and performs well on various screens.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:38,000 --> 00:13:39,000
|
| 651 |
+
When to use it.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:39,000 --> 00:13:46,000
|
| 655 |
+
Use Multi-resolution image when you want your application to adapt to different screen sizes.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:46,000 --> 00:13:54,000
|
| 659 |
+
It's handy for responsive design, making sure your images look cool and well suited for various devices,
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:54,000 --> 00:13:58,000
|
| 663 |
+
from small smartphones to large desktop monitors.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:59,000 --> 00:14:01,000
|
| 667 |
+
Let's review an example.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:01,000 --> 00:14:09,000
|
| 671 |
+
Let's say you have a logo for your app, and you want it to look sharp on both small mobile screens
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:09,000 --> 00:14:12,000
|
| 675 |
+
and large desktop monitors.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:12,000 --> 00:14:20,000
|
| 679 |
+
But for mobile screens, there is no need to upload the heaviest version of an image because mobile
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:20,000 --> 00:14:21,000
|
| 683 |
+
screens are smaller.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:22,000 --> 00:14:29,000
|
| 687 |
+
And that's why there is just no need in uploading heavy version with high resolution that you would
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:29,000 --> 00:14:30,000
|
| 691 |
+
use for TV resolution.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:30,000 --> 00:14:38,000
|
| 695 |
+
For example, you create a multi resolution image for the logo, providing different versions of the
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:38,000 --> 00:14:41,000
|
| 699 |
+
image optimized for different resolutions.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:41,000 --> 00:14:49,000
|
| 703 |
+
When the app runs, the multi resolution image selects the best version based on the screen size, depending
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:49,000 --> 00:14:53,000
|
| 707 |
+
on the selection logic that you would define in the code.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:53,000 --> 00:15:00,000
|
| 711 |
+
In this example, the multi resolution image ensures that the app logo looks great on screens of different
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:00,000 --> 00:15:01,000
|
| 715 |
+
sizes.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:01,000 --> 00:15:08,000
|
| 719 |
+
By dynamically selecting the most suitable version, I create an object of multi resolution image type.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:08,000 --> 00:15:14,000
|
| 723 |
+
In simple words, this object is a container for different resolution of one image.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:14,000 --> 00:15:17,000
|
| 727 |
+
For the sake of this demo I created get logo method.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:18,000 --> 00:15:25,000
|
| 731 |
+
Feel free to explore the source code in details here, but in short I create three image objects and
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:25,000 --> 00:15:34,000
|
| 735 |
+
then I create object of my custom type simple multi resolution image, which in turn implements Multi-resolution
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:34,000 --> 00:15:36,000
|
| 739 |
+
image interface in mass.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:36,000 --> 00:15:42,000
|
| 743 |
+
At get resolution variant, you need to define logic which version of image to provide.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:42,000 --> 00:15:49,000
|
| 747 |
+
Based on the provided screen resolution, you need to come up with some business rules when to return
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:49,000 --> 00:15:50,000
|
| 751 |
+
which image.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:51,000 --> 00:15:55,000
|
| 755 |
+
In this particular case, I just return the first element from the list.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:55,000 --> 00:16:03,000
|
| 759 |
+
In order to simplify the example from logo object, I can get the image that's use the best to the specified
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:03,000 --> 00:16:08,000
|
| 763 |
+
resolution by invoking get resolution variant method.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:08,000 --> 00:16:16,000
|
| 767 |
+
In this case, I just passed some screen width and screen height, and in order to show you the selected
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:16,000 --> 00:16:20,000
|
| 771 |
+
image, I use Jframe from Javax swing package.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:21,000 --> 00:16:23,000
|
| 775 |
+
I set the selected image to the frame.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:24,000 --> 00:16:25,000
|
| 779 |
+
That's how it works.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:25,000 --> 00:16:32,000
|
| 783 |
+
In case you have any questions, please post your questions below the video and I will be happy to answer.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:32,000 --> 00:16:37,000
|
| 787 |
+
Let's review the next feature that was released in Java version nine.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:37,000 --> 00:16:40,000
|
| 791 |
+
Now we are going to review Stack Working API.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:41,000 --> 00:16:49,000
|
| 795 |
+
The Stack Working API in Java nine provides a way to traverse the stack frames of a thread, allowing
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:49,000 --> 00:16:53,000
|
| 799 |
+
you to inspect and manipulate the frames at the runtime.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:53,000 --> 00:17:02,000
|
| 803 |
+
This API is part of the Java Lang package, and it is introduced to replace the older and less flexible
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:02,000 --> 00:17:05,000
|
| 807 |
+
sun reflect reflection.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:05,000 --> 00:17:07,000
|
| 811 |
+
Get color class method.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:07,000 --> 00:17:14,000
|
| 815 |
+
The Stack Working API is particularly useful for various diagnostic and monitoring tools, profilers,
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:14,000 --> 00:17:19,000
|
| 819 |
+
and security frameworks that need to analyze the call stack dynamically.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:19,000 --> 00:17:26,000
|
| 823 |
+
It allows you to walk up and down the stack frames, inspecting information about the classes, methods,
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:26,000 --> 00:17:28,000
|
| 827 |
+
and other details.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:28,000 --> 00:17:33,000
|
| 831 |
+
Here is a brief overview of main components of stack working API.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:34,000 --> 00:17:35,000
|
| 835 |
+
Stack worker class.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:17:36,000 --> 00:17:40,000
|
| 839 |
+
The stack worker class is the entry point to the stack working API.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:17:40,000 --> 00:17:44,000
|
| 843 |
+
It provides factory methods to obtain instances of stack worker.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:17:45,000 --> 00:17:50,000
|
| 847 |
+
You can create a stack worker for the current thread or for a specific thread.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:17:50,000 --> 00:17:53,000
|
| 851 |
+
Basically you can use get instance method.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:17:53,000 --> 00:17:55,000
|
| 855 |
+
It is overloaded.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:17:56,000 --> 00:17:58,000
|
| 859 |
+
Stack frame interface.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:58,000 --> 00:18:03,000
|
| 863 |
+
The stack frame interface represents a single frame in the call stack.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:04,000 --> 00:18:10,000
|
| 867 |
+
It provides methods to retrieve information about the class method, and other details of the frame.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:11,000 --> 00:18:12,000
|
| 871 |
+
Walking the stack.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:13,000 --> 00:18:19,000
|
| 875 |
+
You can use the stack walk walk method to traverse the stack frames.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:19,000 --> 00:18:26,000
|
| 879 |
+
The Walk action interface allows you to define custom actions that are executed for each frame in the
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:18:26,000 --> 00:18:27,000
|
| 883 |
+
stack.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:18:27,000 --> 00:18:31,000
|
| 887 |
+
In the examples that you see on the screen, stack walk.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:18:31,000 --> 00:18:39,000
|
| 891 |
+
Walk is used to walk the stack frames and information about each frame is collected and printed.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:39,000 --> 00:18:46,000
|
| 895 |
+
The stack frame to string method is just one way to obtain information about the frame.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:46,000 --> 00:18:53,000
|
| 899 |
+
You can use various other methods provided by the stack frame interface to access specific details.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:18:54,000 --> 00:19:00,000
|
| 903 |
+
It is important to note that walking the entire stack can have performance implications, and the stack
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:00,000 --> 00:19:05,000
|
| 907 |
+
walking API is intended for diagnostic and monitoring purposes.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:06,000 --> 00:19:14,000
|
| 911 |
+
Always be mindful of the impact on performance when using such APIs, especially in production code.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:19:14,000 --> 00:19:21,000
|
| 915 |
+
The Stack Walker API is useful in scenarios where you need to dynamically inspect the call stack frames
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:19:21,000 --> 00:19:23,000
|
| 919 |
+
of a running Java program.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:23,000 --> 00:19:31,000
|
| 923 |
+
This API is commonly used in various diagnostic and monitoring tools, profiling applications, security
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:31,000 --> 00:19:36,000
|
| 927 |
+
frameworks, and other scenarios where runtime stack analysis is required.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:19:37,000 --> 00:19:43,000
|
| 931 |
+
The next improvement in Java version nine is minor, but still interesting to talk about.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:19:43,000 --> 00:19:49,000
|
| 935 |
+
I am talking about get package name method of the class object in Java nine.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:19:49,000 --> 00:19:56,000
|
| 939 |
+
The get package name method was introduced to the class class, providing a convenient way to retrieve
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:19:56,000 --> 00:19:58,000
|
| 943 |
+
the package name of a class directly.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:19:58,000 --> 00:20:06,000
|
| 947 |
+
Before Java nine, developers often had to use the get package method, followed by calling get name
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:06,000 --> 00:20:07,000
|
| 951 |
+
to get the package name.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:08,000 --> 00:20:14,000
|
| 955 |
+
Actually not a significant change and not too many things to elaborate here.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:14,000 --> 00:20:15,000
|
| 959 |
+
Let's continue.
|
| 960 |
+
|
44 - Java New Versions/002 Source-code-example-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/commit/e53e759c361aedca987fd1a24f9fc2e3a1cb3d63
|
44 - Java New Versions/003 Java 9 Process API & CompletableFuture API updates, Interface Private Methods_en.srt
ADDED
|
@@ -0,0 +1,800 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ine.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:09,000 --> 00:00:16,000
|
| 7 |
+
In Java nine, significant updates were introduced to the process API, providing more control and information
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:16,000 --> 00:00:18,000
|
| 11 |
+
about operating system processes.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:26,000
|
| 15 |
+
These enhancements aim to improve the interaction with native processes and facilitate better management
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:26,000 --> 00:00:28,000
|
| 19 |
+
of external commands and applications.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:29,000 --> 00:00:34,000
|
| 23 |
+
Here are the key features related to process API updates in Java nine.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:35,000 --> 00:00:35,000
|
| 27 |
+
Process.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:37,000
|
| 31 |
+
Handle interface.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:37,000 --> 00:00:43,000
|
| 35 |
+
The process handle interface is introduced in Java nine, offering a handle to a native process.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:44,000 --> 00:00:50,000
|
| 39 |
+
It provides methods to query information about the process, such as the process, ID, parent process,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:50,000 --> 00:00:52,000
|
| 43 |
+
and whether the process is alive.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:00:56,000
|
| 47 |
+
You can obtain a process handle from a process object.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:56,000 --> 00:00:58,000
|
| 51 |
+
Let me show you this on an example.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:59,000 --> 00:01:02,000
|
| 55 |
+
Imagine that I have notepad process.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:02,000 --> 00:01:09,000
|
| 59 |
+
If you run this code on a windows machine, then it will be executed successfully because notepad dot
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:09,000 --> 00:01:14,000
|
| 63 |
+
exe is a default text editor that is present on windows machines.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:15,000 --> 00:01:20,000
|
| 67 |
+
I create instance of process builder type and pass the name of the process.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:20,000 --> 00:01:23,000
|
| 71 |
+
I can start the process by calling start method.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:24,000 --> 00:01:27,000
|
| 75 |
+
Then I receive process object.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:27,000 --> 00:01:34,000
|
| 79 |
+
The process handle interface represents a handle to a native process in the operating system.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:34,000 --> 00:01:38,000
|
| 83 |
+
It was introduced in Java nine as part of the process API updates.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:38,000 --> 00:01:44,000
|
| 87 |
+
The Process handle interface provides methods to obtain information about a process and to interact
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:44,000 --> 00:01:45,000
|
| 91 |
+
with it.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:45,000 --> 00:01:52,000
|
| 95 |
+
It is a more modern way and comprehensive replacement for the older process class.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:52,000 --> 00:01:59,000
|
| 99 |
+
When you call the two handle method on a process object, it returns process handle object associated
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:59,000 --> 00:02:00,000
|
| 103 |
+
with that process.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:01,000 --> 00:02:07,000
|
| 107 |
+
You can use the process handle methods to query information about the process and perform various operations.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:08,000 --> 00:02:09,000
|
| 111 |
+
On exit method.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:09,000 --> 00:02:16,000
|
| 115 |
+
The on exit method is available in the process handle interface, allowing you to define actions to
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:16,000 --> 00:02:19,000
|
| 119 |
+
be executed when the process exits.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:19,000 --> 00:02:27,000
|
| 123 |
+
This method takes a consumer parameter, enabling you to specify behavior such as logging or clean up
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:27,000 --> 00:02:29,000
|
| 127 |
+
after the process terminates.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:29,000 --> 00:02:36,000
|
| 131 |
+
So when I would close notepad process its process ID will be printed to console.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:37,000 --> 00:02:40,000
|
| 135 |
+
Destroy and destroy forcibly masses.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:41,000 --> 00:02:47,000
|
| 139 |
+
The destroy and destroy forcibly masses are available in the process handle interface to terminate the
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:47,000 --> 00:02:49,000
|
| 143 |
+
associated process.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:49,000 --> 00:02:57,000
|
| 147 |
+
The destroy method sends a request to the process to terminate gracefully, while destroy forcibly attempts
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:57,000 --> 00:02:59,000
|
| 151 |
+
to forcibly terminate the process.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:00,000 --> 00:03:07,000
|
| 155 |
+
These enhancements provide better control and visibility into native processes, making it easier to
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:07,000 --> 00:03:13,000
|
| 159 |
+
work with external commands, subprocesses, and system level processes in Java.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:13,000 --> 00:03:14,000
|
| 163 |
+
Applications.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:14,000 --> 00:03:20,000
|
| 167 |
+
The Process Handle interface offers a more comprehensive set of methods for managing and interacting
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:20,000 --> 00:03:26,000
|
| 171 |
+
with processes, contributing to improved process control in Java applications.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:26,000 --> 00:03:33,000
|
| 175 |
+
In case you have any questions, feel free to post them below the video and I will be happy to answer.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:33,000 --> 00:03:41,000
|
| 179 |
+
The next Java nine update that I want to talk about is new methods in Completablefuture API in Java
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:41,000 --> 00:03:41,000
|
| 183 |
+
nine.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:41,000 --> 00:03:48,000
|
| 187 |
+
The Completablefuture API was enhanced with additional methods to support delays and timeouts.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:48,000 --> 00:03:54,000
|
| 191 |
+
These new methods provide more flexibility when dealing with asynchronous computations.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:55,000 --> 00:03:57,000
|
| 195 |
+
Let's review a few of them now.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:57,000 --> 00:04:02,000
|
| 199 |
+
And after that we'll review more of new methods from Completablefuture API.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:03,000 --> 00:04:05,000
|
| 203 |
+
Delayed execute the method.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:06,000 --> 00:04:11,000
|
| 207 |
+
The delayed execute method was introduced to the Completablefuture class.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:11,000 --> 00:04:18,000
|
| 211 |
+
This method allows you to create and execute that introduces a delay before executing tasks.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:19,000 --> 00:04:25,000
|
| 215 |
+
This is useful when you want to introduce a delay before performing an asynchronous operation.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:26,000 --> 00:04:33,000
|
| 219 |
+
In this example, the completablefuture delayed executor that takes as arguments three and time unit
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:33,000 --> 00:04:40,000
|
| 223 |
+
seconds creates an executor that introduces a three second delay before executing the task asynchronously.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:41,000 --> 00:04:45,000
|
| 227 |
+
Or timeout and complete on timeout masses.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:45,000 --> 00:04:52,000
|
| 231 |
+
The all timeout method and the completed timeout method were added to the Completablefuture class to
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:52,000 --> 00:04:53,000
|
| 235 |
+
handle timeouts.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:53,000 --> 00:05:01,000
|
| 239 |
+
The timeout method completes the Completablefuture with a timeout exception if the original computation
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:01,000 --> 00:05:04,000
|
| 243 |
+
takes longer than the specified duration.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:05,000 --> 00:05:13,000
|
| 247 |
+
In this example, you can see that inside callable I imitate time consuming work by putting five second
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:13,000 --> 00:05:14,000
|
| 251 |
+
sleep inside.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:15,000 --> 00:05:20,000
|
| 255 |
+
On the other hand, I create a new future object using or timeout method.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:21,000 --> 00:05:27,000
|
| 259 |
+
In this case, if there is no result within two seconds, then exception will be thrown.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:28,000 --> 00:05:33,000
|
| 263 |
+
There will be execution exception with course timeout exception.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:33,000 --> 00:05:38,000
|
| 267 |
+
I catch it here and print it to console to prove it to you.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:38,000 --> 00:05:44,000
|
| 271 |
+
By the way, if you want to learn more about multi-threading, Completablefuture, API, future type
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:44,000 --> 00:05:50,000
|
| 275 |
+
and other things, feel free to check multi-threading and concurrency section of my course Java from
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:50,000 --> 00:05:52,000
|
| 279 |
+
zero to first job.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:52,000 --> 00:05:58,000
|
| 283 |
+
There are a lot of examples and lessons that will help you to learn multi-threading in Java.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:58,000 --> 00:06:05,000
|
| 287 |
+
The complete on timeout method completes the Completablefuture with a default value if the original
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:05,000 --> 00:06:10,000
|
| 291 |
+
computation takes longer than the specified duration.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:11,000 --> 00:06:14,000
|
| 295 |
+
In the similar example, we wouldn't get timeout exception.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:15,000 --> 00:06:18,000
|
| 299 |
+
Instead, we'll just receive default value.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:18,000 --> 00:06:25,000
|
| 303 |
+
Both of these methods provide a convenient way to handle timeouts in asynchronous computations.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:26,000 --> 00:06:33,000
|
| 307 |
+
These additions in Java nine enhance the Completablefuture API, making it more powerful and expressive
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:33,000 --> 00:06:36,000
|
| 311 |
+
when dealing with asynchronous and concurrent programming.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:37,000 --> 00:06:43,000
|
| 315 |
+
They enable developers to control and manage delays and timeouts in a more straightforward manner.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:44,000 --> 00:06:47,000
|
| 319 |
+
There are some more updates to Completablefuture API.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:47,000 --> 00:06:49,000
|
| 323 |
+
Let's review them.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:49,000 --> 00:06:51,000
|
| 327 |
+
Default executor method.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:51,000 --> 00:06:56,000
|
| 331 |
+
The default executor method is a new method introduced in Java nine.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:56,000 --> 00:07:05,000
|
| 335 |
+
It returns the default executor used for asynchronous execution of dependent tasks when not explicitly
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:05,000 --> 00:07:06,000
|
| 339 |
+
specified.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:06,000 --> 00:07:14,000
|
| 343 |
+
In this example, the default executor method is used to obtain the default executor and then then accept.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:14,000 --> 00:07:21,000
|
| 347 |
+
Async is invoked with the executor for the asynchronous execution of the dependent task.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:22,000 --> 00:07:25,000
|
| 351 |
+
But what is the type of default executor?
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:25,000 --> 00:07:28,000
|
| 355 |
+
It is Java.util.concurrent Forkjoinpool.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:29,000 --> 00:07:31,000
|
| 359 |
+
New incomplete future method.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:32,000 --> 00:07:39,000
|
| 363 |
+
The new incomplete future method in the Completablefuture class is a factory method that creates a new
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:39,000 --> 00:07:42,000
|
| 367 |
+
incomplete Completablefuture instance.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:42,000 --> 00:07:50,000
|
| 371 |
+
This method returns a new Completablefuture that is initially neither completed nor exceptionally completed.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:50,000 --> 00:07:56,000
|
| 375 |
+
This method is particularly useful in scenarios where you want to manually control the completion of
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:56,000 --> 00:07:58,000
|
| 379 |
+
Completablefuture instance.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:59,000 --> 00:08:06,000
|
| 383 |
+
By obtaining an incomplete completablefuture, you have the flexibility to complete it with a value
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:06,000 --> 00:08:10,000
|
| 387 |
+
or an exception at a later point in your code.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:10,000 --> 00:08:16,000
|
| 391 |
+
This method is typically used in custom scenarios, where you want to manually manage the completion
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:16,000 --> 00:08:20,000
|
| 395 |
+
of a Completablefuture, and here you can find an example.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:20,000 --> 00:08:26,000
|
| 399 |
+
I create incomplete future and pass it to the perform async operation method.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:27,000 --> 00:08:35,000
|
| 403 |
+
Here you can see I call complete method on the future variable, and later I call join method on incomplete
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:35,000 --> 00:08:39,000
|
| 407 |
+
future object to join it to the main thread of execution.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:40,000 --> 00:08:44,000
|
| 411 |
+
This short example illustrates how you can apply this on practice.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:45,000 --> 00:08:46,000
|
| 415 |
+
Copy Macid.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:46,000 --> 00:08:52,000
|
| 419 |
+
The copy method creates and returns a copy of the current Completablefuture instance.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:52,000 --> 00:08:59,000
|
| 423 |
+
The copy method is useful when you want to create an independent copy of an existing Completablefuture
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:59,000 --> 00:09:01,000
|
| 427 |
+
to apply different operations.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:02,000 --> 00:09:05,000
|
| 431 |
+
Minimal completion stage method.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:05,000 --> 00:09:12,000
|
| 435 |
+
The minimal completion stage method returns a completion stage view of the current Completeable feature.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:12,000 --> 00:09:16,000
|
| 439 |
+
This allows working with a broader completion stage API.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:16,000 --> 00:09:23,000
|
| 443 |
+
This can be useful when you need to interact with libraries or methods that work with the more general
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:23,000 --> 00:09:24,000
|
| 447 |
+
completion stage.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:24,000 --> 00:09:25,000
|
| 451 |
+
Interface.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:25,000 --> 00:09:31,000
|
| 455 |
+
If you are working with library or methods that expects a completion stage and you have Completeable
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:31,000 --> 00:09:37,000
|
| 459 |
+
future, using minimal completion stage allows you to seamlessly integrate your completeable future
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:37,000 --> 00:09:40,000
|
| 463 |
+
into a more generic completion stage context.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:41,000 --> 00:09:48,000
|
| 467 |
+
In this example, we have Completeable future and we obtain a completion stage view of it using Completeable
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:48,000 --> 00:09:51,000
|
| 471 |
+
future minimal completion stage.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:52,000 --> 00:09:59,000
|
| 475 |
+
The process with completion stage method then demonstrates using the completion Stage API, showing
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:59,000 --> 00:10:05,000
|
| 479 |
+
how you can chain asynchronous operations, handle success, and handle exceptions.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:06,000 --> 00:10:13,000
|
| 483 |
+
This method allows you to work with the broader completion stage interface, while still utilizing the
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:13,000 --> 00:10:16,000
|
| 487 |
+
features provided by Completablefuture.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:16,000 --> 00:10:23,000
|
| 491 |
+
It's a way to bridge between the specific features of Completablefuture and the more general completion
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:23,000 --> 00:10:30,000
|
| 495 |
+
stage interface when needed for compatibility or consistency reasons in your code base.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:31,000 --> 00:10:37,000
|
| 499 |
+
In case you would have any questions, please let me know below the video and I will be happy to answer.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:39,000 --> 00:10:40,000
|
| 503 |
+
Complete a sync message.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:41,000 --> 00:10:48,000
|
| 507 |
+
The complete A sync message completes the completablefuture A synchronously using the specified supplier
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:48,000 --> 00:10:49,000
|
| 511 |
+
to generate the result.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:50,000 --> 00:10:55,000
|
| 515 |
+
These methods allow you to complete the Completablefuture asynchronously, providing a more flexible
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:55,000 --> 00:10:57,000
|
| 519 |
+
way to produce the result.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:57,000 --> 00:11:03,000
|
| 523 |
+
These additions in Java nine provide a more options and flexibility when working with Completablefuture.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:03,000 --> 00:11:11,000
|
| 527 |
+
They enable better control and customization of asynchronous computations, making it easier to integrate
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:11,000 --> 00:11:15,000
|
| 531 |
+
with different execution environments and scenarios.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:15,000 --> 00:11:20,000
|
| 535 |
+
There is one more interesting feature that was introduced in Java version nine.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:20,000 --> 00:11:23,000
|
| 539 |
+
It is Interface Private Methods.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:23,000 --> 00:11:31,000
|
| 543 |
+
In Java nine, a new feature was introduced that allows interface methods to have private implementation.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:31,000 --> 00:11:38,000
|
| 547 |
+
Before Java nine, all methods in an interface were implicitly public and abstract.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:38,000 --> 00:11:44,000
|
| 551 |
+
With the addition of private methods in interfaces, developers can include helper methods that are
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:44,000 --> 00:11:50,000
|
| 555 |
+
used only within the interface, making the code more modular and maintainable.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:51,000 --> 00:11:54,000
|
| 559 |
+
I decided to put this example in the separate file.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:54,000 --> 00:11:57,000
|
| 563 |
+
The file is called interface Private methods demo.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:58,000 --> 00:12:07,000
|
| 567 |
+
As you can see here is a calculator interface and multiply method is the default one that uses private
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:07,000 --> 00:12:08,000
|
| 571 |
+
method inside.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:08,000 --> 00:12:11,000
|
| 575 |
+
Basically you just put private modifier.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:11,000 --> 00:12:16,000
|
| 579 |
+
You don't need to add any other modifiers like default or any other ones.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:16,000 --> 00:12:25,000
|
| 583 |
+
This private helper method is only accessible within the interface and can be accessed by classes implementing
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:25,000 --> 00:12:26,000
|
| 587 |
+
the interface.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:27,000 --> 00:12:34,000
|
| 591 |
+
This feature enhances the expressiveness and maintainability of code in interface, by allowing developers
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:34,000 --> 00:12:40,000
|
| 595 |
+
to encapsulate implementation details that are not part of the public API.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:40,000 --> 00:12:48,000
|
| 599 |
+
It is important to note that private methods in interfaces can't be overridden or accessed by implementing
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:48,000 --> 00:12:49,000
|
| 603 |
+
classes.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:49,000 --> 00:12:54,000
|
| 607 |
+
They are intended purely for internal use within the interface itself.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:55,000 --> 00:12:59,000
|
| 611 |
+
So remember this and use this when it would be needed.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:59,000 --> 00:13:04,000
|
| 615 |
+
Let's review the next Java nine update in Java nine.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:04,000 --> 00:13:10,000
|
| 619 |
+
Two new attributes since and for removal were introduced to the deprecated annotation.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:11,000 --> 00:13:17,000
|
| 623 |
+
These attributes provide additional information about the deprecation of a class, method, field,
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:17,000 --> 00:13:18,000
|
| 627 |
+
or interface.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:19,000 --> 00:13:26,000
|
| 631 |
+
The since attribute allows developers to specify the version in which the annotated element was deprecated.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:27,000 --> 00:13:33,000
|
| 635 |
+
It is helpful for providing information about when the deprecation occurred, making it easier for developers
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:33,000 --> 00:13:35,000
|
| 639 |
+
to understand the deprecation.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:35,000 --> 00:13:36,000
|
| 643 |
+
History.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:37,000 --> 00:13:44,000
|
| 647 |
+
The removal attribute is a Boolean flag that signals whether the annotated element is intended for removal
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:44,000 --> 00:13:46,000
|
| 651 |
+
in the future versions.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:46,000 --> 00:13:53,000
|
| 655 |
+
It provides a way to convey the deprecated elements is planned for removal in subsequent releases.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:54,000 --> 00:13:59,000
|
| 659 |
+
For the sake of the demo, I added deprecated annotation with these new attributes above.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:59,000 --> 00:14:00,000
|
| 663 |
+
Subtract method.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:01,000 --> 00:14:06,000
|
| 667 |
+
Also in Java nine, there is a preview of new Http client API.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:06,000 --> 00:14:13,000
|
| 671 |
+
But before learning the details of new Http client API, let's try to understand what does previous
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:13,000 --> 00:14:16,000
|
| 675 |
+
status mean and how it is different from the release.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:17,000 --> 00:14:24,000
|
| 679 |
+
A preview feature means that the feature is included in the release for developers to try out and provide
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:24,000 --> 00:14:30,000
|
| 683 |
+
feedback, but it is not yet finalized and may undergo changes based on user feedback.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:31,000 --> 00:14:34,000
|
| 687 |
+
Here are some key points regarding preview features.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:34,000 --> 00:14:35,000
|
| 691 |
+
Usability.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:36,000 --> 00:14:43,000
|
| 695 |
+
You can use preview features in your Java code, including the new Http client API, by enabling preview
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:43,000 --> 00:14:45,000
|
| 699 |
+
language features in the Java compiler.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:45,000 --> 00:14:52,000
|
| 703 |
+
You can do this by adding the Enable Preview option when compiling or running your code.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:53,000 --> 00:14:54,000
|
| 707 |
+
Feedback.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:54,000 --> 00:15:01,000
|
| 711 |
+
The inclusion of a feature as a preview is an opportunity for developers to try it out and provide feedback
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:01,000 --> 00:15:02,000
|
| 715 |
+
to the Java development team.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:03,000 --> 00:15:09,000
|
| 719 |
+
Feedback is valuable for identifying issues, making improvements, and ensuring that the feature meets
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:09,000 --> 00:15:12,000
|
| 723 |
+
the needs of the development community.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:12,000 --> 00:15:14,000
|
| 727 |
+
Potential changes.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:14,000 --> 00:15:20,000
|
| 731 |
+
Since preview features are not finalized, there is a possibility that the feature may undergo changes
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:20,000 --> 00:15:22,000
|
| 735 |
+
based on feedback.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:22,000 --> 00:15:29,000
|
| 739 |
+
This means that code written using preview features might need adjustments in later versions of Java.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:30,000 --> 00:15:33,000
|
| 743 |
+
Stability and compatibility.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:33,000 --> 00:15:39,000
|
| 747 |
+
While preview features are intended for experimentation and feedback, they are not guaranteed to be
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:39,000 --> 00:15:43,000
|
| 751 |
+
as stable or compatible as finalized features.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:44,000 --> 00:15:50,000
|
| 755 |
+
It is generally not recommended to use preview features in production code that requires a long terme
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:50,000 --> 00:15:51,000
|
| 759 |
+
stability.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:52,000 --> 00:15:53,000
|
| 763 |
+
Official release.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:53,000 --> 00:16:00,000
|
| 767 |
+
Once a feature has received sufficient feedback and any necessary refinements have been made, it may
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:00,000 --> 00:16:06,000
|
| 771 |
+
be promoted to the fully supported and finalized feature in subsequent Java releases.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:06,000 --> 00:16:11,000
|
| 775 |
+
At that point, you can use the feature without the need for the Enable Preview option.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:12,000 --> 00:16:19,000
|
| 779 |
+
Regarding the new Http client API, it is a powerful and modern API designed to replace the legacy Http
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:19,000 --> 00:16:21,000
|
| 783 |
+
url connection API.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:21,000 --> 00:16:27,000
|
| 787 |
+
While it was initially introduced as a preview feature in Java nine, it has been refined and improved
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:27,000 --> 00:16:28,000
|
| 791 |
+
in subsequent releases.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:29,000 --> 00:16:35,000
|
| 795 |
+
The feature was released in Java 11, so we will learn it in details in the separate lesson when we
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:35,000 --> 00:16:38,000
|
| 799 |
+
will learn features of Java 11.
|
| 800 |
+
|
44 - Java New Versions/003 Source-code-example-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/commit/e53e759c361aedca987fd1a24f9fc2e3a1cb3d63
|