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
+33-36Lines changed: 33 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1117,41 +1117,38 @@ const araba = new Araba('Ford','F-150','kirmizi')
1117
1117
```
1118
1118
**[⬆ en başa dön](#içindekiler)**
1119
1119
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)
1137
1134
1138
1135
**Kötü:**
1139
1136
```javascript
1140
-
classEmployee {
1141
-
constructor(name, email) {
1142
-
this.name=name;
1143
-
this.email=email;
1137
+
classPersonel {
1138
+
constructor(isim, mail) {
1139
+
this.isim=isim;
1140
+
this.mail=mail;
1144
1141
}
1145
1142
1146
1143
// ...
1147
1144
}
1148
1145
1149
-
//Bad because Employees "have" tax data. EmployeeTaxData is not a type of Employee
1150
-
classEmployeeTaxDataextendsEmployee {
1151
-
constructor(ssn, salary) {
1146
+
//Kötü çünkü Personeller vergi verisine "sahip". PersonelVergiVerileri, bir Personel türü değil.
1147
+
classPersonelVergiVerileriextendsPersonel {
1148
+
constructor(ssn, maas) {
1152
1149
super();
1153
-
this.ssn= ssn;
1154
-
this.salary=salary;
1150
+
this.ssn= ssn;// sosyal güvenlik numarası
1151
+
this.maas=maas;
1155
1152
}
1156
1153
1157
1154
// ...
@@ -1160,23 +1157,23 @@ class EmployeeTaxData extends Employee {
0 commit comments