-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inheritance, Polymorphism, Abstract example
- Loading branch information
Showing
9 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hasankaya.oopexample | ||
|
||
open class Animal { | ||
open fun breathe(){ | ||
println("Breathing!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hasankaya.oopexample | ||
|
||
class Dog: Animal() { | ||
fun test(){ | ||
super.breathe() | ||
//miras aldığımız sınıftaki fonksiyonu çalıştırır. | ||
} | ||
|
||
override fun breathe(){ | ||
println("dog breathe") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hasankaya.oopexample | ||
//interface içerisinde property yazmak | ||
interface HouseDecor { | ||
//%100 abstract | ||
// kotlin -> no initialize for properties | ||
//java -> must initialize | ||
|
||
var roomName: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.hasankaya.oopexample | ||
//interface içerisinde fonksiyon yazmak | ||
interface Instrument { | ||
//java -> no body | ||
//kotlin -> body olabilir de olmayabilir de | ||
fun info() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.hasankaya.oopexample | ||
|
||
class MallShops(shopName: String, shopCode: Int, mallId: Int) : Shops(shopName, shopCode, mallId) { | ||
|
||
fun floorType(){ | ||
println("floor type") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hasankaya.oopexample | ||
|
||
class Matcalculates { | ||
fun sum(): Int {return 0} | ||
fun sum(x:Int, y:Int):Int{return x+y} | ||
fun sum(x:Int, y:Int, z:Int): Int{return x+y+z} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hasankaya.oopexample | ||
|
||
class Piano: HouseDecor, Instrument { | ||
override var roomName: String | ||
get() = "kitchen" | ||
set(value) {} | ||
|
||
override fun info() { | ||
TODO("Not yet implemented") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package com.hasankaya.oopexample | ||
|
||
class Shops(shopName: String, shopCode: Int, mallId:Int ) { | ||
//biz sınıfların başına open yazmazsak, default olarak final tipinde tanımlanır ve başka yerde kullandırmaz. | ||
//eğer open yazarsak inheritance alabiliriz . | ||
open class Shops(shopName: String, shopCode: Int, mallId:Int ) { | ||
//encapsulation örneği | ||
var shopName: String?= shopName | ||
private set //değişime izin vermiyoruz bu şekilde. | ||
get //verinin okunmasına izin veriyoruz. | ||
set | ||
get | ||
var shopCode: Int?= shopCode | ||
set | ||
get | ||
var mallId: Int?=mallId | ||
get | ||
private set | ||
get//verinin okunmasına izin veriyoruz.(encapsulation) | ||
private set//değişime izin vermiyoruz bu şekilde.(encapsulation) | ||
|
||
private val softwareType: String="Enterprice" | ||
|
||
fun returnSoftwareType(password: String):String{ | ||
if(password=="hasan"){ | ||
return softwareType; | ||
}else{ | ||
return "wrong pass!" | ||
} | ||
} | ||
|
||
|
||
|
||
} |