Skip to content

Commit dc994d1

Browse files
52
# Conflicts: # README.md
2 parents 878de51 + 5b8a2b9 commit dc994d1

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Sooner or later I will complete it with the relative answers. Feel free to contr
5555
* [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)
5656
* [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)
5757
* [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)
5959
* 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)
6161
* Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.
6262
* How would you deal with Dependency Hell?
6363
* 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 {
560560
```
561561
<br>[⬆ Back to top](#table-of-contents)
562562

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+
class Book {
574+
constructor(pages) {
575+
this.pages = pages;
576+
}
577+
}
578+
579+
const myBook = new Book([{ text: 'content of the title page'}, { text: '...'}]);
580+
const titlePage = myBook.pages[0];
581+
```
582+
583+
Fixed:
584+
```javascript
585+
class Book {
586+
constructor(title, pages) {
587+
this.title = title;
588+
this.pages = pages;
589+
}
590+
591+
getTitlePage() {
592+
return this.pages[0];
593+
}
594+
}
595+
596+
const myBook = new Book([{ text: 'content of the title page'}, { text: '...'}]);
597+
const titlePage = myBook.getTitlePage();
598+
```
599+
<br>[⬆ Back to top](#table-of-contents)
600+
563601
### 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?
564602

565603
1. Those objects are hard to test - they are tied to the data layer.

0 commit comments

Comments
 (0)