You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-2Lines changed: 40 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,9 @@ Sooner or later I will complete it with the relative answers. Feel free to contr
55
55
*[Data-Mapper is a design pattern that promotes the use of a layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. On the contrary, in Active-Record objects directly incorporate operations for persisting themselves to a database, and properties corresponding to the underlying database tables. Do you have an opinion on those patterns? When would you use one instead of the other?](#data-mapper-is-a-design-pattern-that-promotes-the-use-of-a-layer-of-mappers-that-moves-data-between-objects-and-a-database-while-keeping-them-independent-of-each-other-and-the-mapper-itself-on-the-contrary-in-active-record-objects-directly-incorporate-operations-for-persisting-themselves-to-a-database-and-properties-corresponding-to-the-underlying-database-tables-do-you-have-an-opinion-on-those-patterns-when-would-you-use-one-instead-of-the-other)
56
56
*[Why is it often said that the introduction of `null` is a "billion dollar mistake"? Would you discuss the techniques to avoid it, such as the Null Object Pattern introduced by the GOF book, or Option types?](#why-is-it-often-said-that-the-introduction-of-null-is-a-billion-dollar-mistake-would-you-discuss-the-techniques-to-avoid-it-such-as-the-null-object-pattern-introduced-by-the-gof-book-or-option-types)
57
57
*[Many state that, in Object-Oriented Programming, composition is often a better option than inheritance. What's you opinion?](#many-state-that-in-object-oriented-programming-composition-is-often-a-better-option-than-inheritance-whats-you-opinion)
58
-
* What is an Anti-corruption Layer?
58
+
*[What is an Anti-corruption Layer?](#what-is-an-anti-corruption-layer)
59
59
* Singleton is a design pattern that restricts the instantiation of a class to one single object. Writing a Thread-Safe Singleton class is not so obvious. Would you try?
60
-
* The ability to change implementation without affecting clients is called Data Abstraction. Produce an example violating this property, then fix it.
60
+
*[The ability to change implementation without affecting clients is called Data Abstraction. Produce an example violating this property, then fix it.](#the-ability-to-change-implementation-without-affecting-clients-is-called-data-abstraction-produce-an-example-violating-this-property-then-fix-it)
61
61
* Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.
62
62
* How would you deal with Dependency Hell?
63
63
* Is goto evil? You may have heard of the famous paper "Go To Statement Considered Harmful" by Edsger Dijkstra, in which he criticized the use of the `goto` statement and advocated structured programming instead. The use of `goto` has always been controversial, so much that even Dijkstra's letter was criticized with articles such as "'GOTO Considered Harmful' Considered Harmful". What's your opinion on the use of `goto`?
@@ -560,6 +560,44 @@ class Crew {
560
560
```
561
561
<br>[⬆ Back to top](#table-of-contents)
562
562
563
+
### What is an Anti-corruption Layer?
564
+
565
+
It's a layer in the system which is responsible for communication between subsystems (most likely with the external or legacy system) which don't operate on the same models.
566
+
Its purpose is to create an isolating layer which provides clients with functionality in terms of their own domain model.
567
+
<br>[⬆ Back to top](#table-of-contents)
568
+
569
+
### The ability to change implementation without affecting clients is called Data Abstraction. Produce an example violating this property, then fix it.
570
+
571
+
Data Abstraction violation:
572
+
```javascript
573
+
classBook {
574
+
constructor(pages) {
575
+
this.pages= pages;
576
+
}
577
+
}
578
+
579
+
constmyBook=newBook([{ text:'content of the title page'}, { text:'...'}]);
580
+
consttitlePage=myBook.pages[0];
581
+
```
582
+
583
+
Fixed:
584
+
```javascript
585
+
classBook {
586
+
constructor(title, pages) {
587
+
this.title= title;
588
+
this.pages= pages;
589
+
}
590
+
591
+
getTitlePage() {
592
+
returnthis.pages[0];
593
+
}
594
+
}
595
+
596
+
constmyBook=newBook([{ text:'content of the title page'}, { text:'...'}]);
597
+
consttitlePage=myBook.getTitlePage();
598
+
```
599
+
<br>[⬆ Back to top](#table-of-contents)
600
+
563
601
### Active-Record is the design pattern that promotes objects to include functions such as Insert, Update, and Delete, and properties that correspond to the columns in some underlying database table. In your opinion and experience, which are the limits and pitfalls of the this pattern?
564
602
565
603
1. Those objects are hard to test - they are tied to the data layer.
0 commit comments