Skip to content

Commit 426b5da

Browse files
committed
Prefer composition over inheritance çevirildi
1 parent 83f6009 commit 426b5da

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

‎README.md

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,41 +1117,38 @@ const araba = new Araba('Ford','F-150','kirmizi')
11171117
```
11181118
**[⬆ en başa dön](#içindekiler)**
11191119

1120-
### Prefer composition over inheritance
1121-
As stated famously in [*Design Patterns*](https://en.wikipedia.org/wiki/Design_Patterns) by the Gang of Four,
1122-
you should prefer composition over inheritance where you can. There are lots of
1123-
good reasons to use inheritance and lots of good reasons to use composition.
1124-
The main point for this maxim is that if your mind instinctively goes for
1125-
inheritance, try to think if composition could model your problem better. In some
1126-
cases it can.
1127-
1128-
You might be wondering then, "when should I use inheritance?" It
1129-
depends on your problem at hand, but this is a decent list of when inheritance
1130-
makes more sense than composition:
1131-
1132-
1. Your inheritance represents an "is-a" relationship and not a "has-a"
1133-
relationship (Human->Animal vs. User->UserDetails).
1134-
2. You can reuse code from the base classes (Humans can move like all animals).
1135-
3. You want to make global changes to derived classes by changing a base class.
1136-
(Change the caloric expenditure of all animals when they move).
1120+
### Miras(Kalıtım) yerine Kompozisyonu tercih edin
1121+
Gang of Four tarafından [*Design Patterns*](https://en.wikipedia.org/wiki/Design_Patterns) da ünlü olarak belirtildiği gibi, yapabildiğiniz yerlerde miras(kalıtım) yerine kompozisyonu tercih etmelisiniz. Miras(kalıtım)ı
1122+
kullanmak için birçok iyi sebep olduğu gibi kompozisyonu kullanmak içinde birçok iyi sebep var. Bu kural için
1123+
asıl nokta, eğer aklınız içgüdüsel olarak miras(kalıtım)ı tercih ediyorsa, kompozisyonun, probleminizi daha iyi
1124+
modelleyebileceğini düşünmeye çalışın. Bazı durumlarda bu olabilir.
1125+
1126+
"Miras(kalıtım)ı ne zaman kullanmalıyım?" diye merak ediyor olabilirsiniz. Bu durum elinizdeki soruna bağlı ama
1127+
bu, ne zaman miras(kalıtım)ın kompozisyondan daha anlamlı olduğunun kabul edilebilir bir listesi.
1128+
1129+
1. Miras(kalıtım)ınız, "-dır, -dir" ilişkisini sağlıyor ve "sahiplik" ilişkisinin sağlamıyor.
1130+
(İnsan->Hayvan vs. Kullanıcı->KullanıcıDetayları)
1131+
2. Kodu temel sınıflardan yeniden kullanabilirsiniz. (İnsanlar, tüm hayvanlar gibi hareket edebilir)
1132+
3. Bir temel sınıfı değiştirerek türetilmiş sınıflarda genel değişiklikler yapmak istiyorsunuz.
1133+
(Hayvanların hareket ettiğinde harcadığı kaloriyi değiştirmek)
11371134

11381135
**Kötü:**
11391136
```javascript
1140-
class Employee {
1141-
constructor(name, email) {
1142-
this.name = name;
1143-
this.email = email;
1137+
class Personel {
1138+
constructor(isim, mail) {
1139+
this.isim = isim;
1140+
this.mail = mail;
11441141
}
11451142

11461143
// ...
11471144
}
11481145

1149-
// Bad because Employees "have" tax data. EmployeeTaxData is not a type of Employee
1150-
class EmployeeTaxData extends Employee {
1151-
constructor(ssn, salary) {
1146+
// Kötü çünkü Personeller vergi verisine "sahip". PersonelVergiVerileri, bir Personel türü değil.
1147+
class PersonelVergiVerileri extends Personel {
1148+
constructor(ssn, maas) {
11521149
super();
1153-
this.ssn = ssn;
1154-
this.salary = salary;
1150+
this.ssn = ssn; // sosyal güvenlik numarası
1151+
this.maas = maas;
11551152
}
11561153

11571154
// ...
@@ -1160,23 +1157,23 @@ class EmployeeTaxData extends Employee {
11601157

11611158
**İyi:**
11621159
```javascript
1163-
class EmployeeTaxData {
1164-
constructor(ssn, salary) {
1165-
this.ssn = ssn;
1166-
this.salary = salary;
1160+
class PersonelVergiVerileri {
1161+
constructor(ssn, maas) {
1162+
this.ssn = ssn; // sosyal güvenlik numarası
1163+
this.maas = maas;
11671164
}
11681165

11691166
// ...
11701167
}
11711168

1172-
class Employee {
1173-
constructor(name, email) {
1174-
this.name = name;
1175-
this.email = email;
1169+
class Personel {
1170+
constructor(isim, mail) {
1171+
this.isim = isim;
1172+
this.mail = mail;
11761173
}
11771174

1178-
setTaxData(ssn, salary) {
1179-
this.taxData = new EmployeeTaxData(ssn, salary);
1175+
vergiVerisiniBelirle(ssn, maas) {
1176+
this.vergiVerisi = new PersonelVergiVerileri(ssn, maas);
11801177
}
11811178
// ...
11821179
}

0 commit comments

Comments
 (0)