All Projects → ashtanko → OOD-Principles-Kotlin

ashtanko / OOD-Principles-Kotlin

Licence: other
The Principles of OOD in Kotlin 1.3.61

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to OOD-Principles-Kotlin

Ood Principles In Swift
💎 The Principles of OOD (SOLID) based on Uncle Bob articles.
Stars: ✭ 1,710 (+14150%)
Mutual labels:  liskov-substitution-principle, dependency-inversion-principle, interface-segregation-principle, single-responsibility-principle
job-interview-solid-principles-test
A programming job interview questions that test the understanding of basic principles and patterns
Stars: ✭ 32 (+166.67%)
Mutual labels:  principles, solid-principles
Designpatternslibrary
A comprehensive design patterns library implemented in C#, which covers various design patterns from the most commonly used ones to the lesser-known ones. Get familiar with and learn design patterns through moderately realistic examples.
Stars: ✭ 485 (+3941.67%)
Mutual labels:  principles
hacker-laws-tr
💻📖 Programcıların faydalı bulacağı yasalar, teoriler, prensipler ve desenler. #hackerlaws
Stars: ✭ 810 (+6650%)
Mutual labels:  principles
Clean Code Javascript
🛁 Clean Code cho Javascript: một số lời khuyên để giữ cho code js của bạn luôn sạch sẽ thơm tho 💪 💪 💪
Stars: ✭ 166 (+1283.33%)
Mutual labels:  principles
Design Patterns For Humans
An ultra-simplified explanation to design patterns
Stars: ✭ 32,376 (+269700%)
Mutual labels:  principles
Write Readable Javascript Code
📖 All about writing maintainable JavaScript
Stars: ✭ 244 (+1933.33%)
Mutual labels:  principles
Ui Design
🔥 A curated list of useful resources related to User Interface Design
Stars: ✭ 423 (+3425%)
Mutual labels:  principles
Dermayon
Dermayon is Library for supporting build large application,distributed application, scalable, microservices, cqrs, event sourcing, including generic ef repository pattern with unit of work, generic mongo repository pattern with unit of work, kafka, etc
Stars: ✭ 66 (+450%)
Mutual labels:  solid-principles
Books
Books worth spreading
Stars: ✭ 161 (+1241.67%)
Mutual labels:  principles
api-principles
The applicable SBB API Principles
Stars: ✭ 31 (+158.33%)
Mutual labels:  principles
State Of The Art Shitcode
💩State-of-the-art shitcode principles your project should follow to call it a proper shitcode
Stars: ✭ 2,207 (+18291.67%)
Mutual labels:  principles
Hacker Laws Zh
💻📖对开发人员有用的定律、理论、原则和模式。(Laws, Theories, Principles and Patterns that developers will find useful.)
Stars: ✭ 9,446 (+78616.67%)
Mutual labels:  principles
Data Making Guidelines
📘 Making Data, the DataMade Way
Stars: ✭ 248 (+1966.67%)
Mutual labels:  principles
Ood Principles Kotlin
The Principles of OOD in Kotlin 1.0.2
Stars: ✭ 9 (-25%)
Mutual labels:  principles
composing-go-example
Project example demonstrating interface segregation in go
Stars: ✭ 21 (+75%)
Mutual labels:  interface-segregation-principle
Awesome Artificial Intelligence Guidelines
This repository aims to map the ecosystem of artificial intelligence guidelines, principles, codes of ethics, standards, regulation and beyond.
Stars: ✭ 449 (+3641.67%)
Mutual labels:  principles
Clean Code Javascript
🛁 Clean Code concepts adapted for JavaScript
Stars: ✭ 62,912 (+524166.67%)
Mutual labels:  principles
Clean Code Javascript Tr
JavaScript için Uyarlanmış Temiz Kod Kavramları
Stars: ✭ 232 (+1833.33%)
Mutual labels:  principles
programming-principles
Categorized overview of Programming Principles & Patterns
Stars: ✭ 289 (+2308.33%)
Mutual labels:  principles

The Principles of OOD in Kotlin 1.3.61

S.O.L.I.D.

🔐 The Single Responsibility Principle

A class should have one, and only one, reason to change. (read more)

Example:

interface CanBeOpened {
    fun open()
}

interface CanBeClosed {
    fun closed()
}

// I'm the door. I have an encapsulated state and you can change it using methods.
class PodBayDoor : CanBeOpened, CanBeClosed {

    private enum class State {
        Open, Closed
    }

    private var state: State = State.Closed

    override fun open() {
        state = State.Open
    }

    override fun closed() {
        state = State.Closed
    }
}

// I'm only responsible for opening, no idea what's inside or how to close.
class DoorOpener(private val door: CanBeOpened) {

    fun execute() {
        door.open()
    }

}

// I'm only responsible for closing, no idea what's inside or how to open.
class DoorCloser(private val door: CanBeClosed) {

    fun execute() {
        door.closed()
    }

}

val door = PodBayDoor()

Only the DoorOpener is responsible for opening the door.

val doorOpener = DoorOpener(door)
doorOpener.execute()

If another operation should be made upon closing the door, like switching on the alarm, you don't have to change the DoorOpener class.

val doorCloser = DoorCloser(door)
doorCloser.execute()

The Open Closed Principle

You should be able to extend a classes behavior, without modifying it. (read more)

Example:

interface CanShoot {
    fun shoot(): String
}

// I'm a laser beam. I can shoot.
class LaserBeam : CanShoot {
    override fun shoot(): String {
        return "Ziiiip!"
    }
}

// I have weapons and trust me I can fire them all at once. Boom! Boom! Boom!
class WeaponsComposite(var weapons: Array<CanShoot>) {
    fun shoot(): String {
        return weapons.map { it.shoot() }[0]
    }
}

val laser = LaserBeam()
var weapons = WeaponsComposite(weapons = arrayOf(laser))

weapons.shoot()

I'm a rocket launcher. I can shoot a rocket.

⚠️ To add rocket launcher support I don't need to change anything in existing classes.

class RocketLauncher : CanShoot {
    override fun shoot(): String {
        return "Whoosh!"
    }
}


val rocket = RocketLauncher()

weapons = WeaponsComposite(weapons = arrayOf(laser, rocket))
weapons.shoot()

👥 The Liskov Substitution Principle

Derived classes must be substitutable for their base classes. (read more)

Example:

private interface Bird {
    fun eat() {
        println("Eat!")
    }
}

private interface FlightBird : Bird {
    fun fly() {
        println("Fly!")
    }
}

private interface NonFlightBird : Bird {

}

private class Crow : FlightBird {

    override fun fly() {
        super.fly()

        println("It is Crow - it can fly")
    }

    override fun eat() {
        super.eat()
    }
}

private class Ostrich : NonFlightBird {
    override fun eat() {
        super.eat()
        println("It is Ostrich - it can eat but it can't fly")
    }
}

🍴 The Interface Segregation Principle

Make fine grained interfaces that are client specific. (read more)

Example:

interface LandingSiteHaving {
    var landingSite: String
}

interface Landing {
    fun landOn(on: LandingSiteHaving): String
}

interface PayloadHaving {
    var payload: String
}

class InternationalSpaceStation {

    fun fetchPayload(vehicle: PayloadHaving): String {
        return "Deployed ${vehicle.payload} at April 10, 2016, 11:23 UTC"
    }
}

class OfCourseIStillLoveYouBarge : LandingSiteHaving {
    override var landingSite = "a barge on the Atlantic Ocean"
}

class SpaceXCRS8 : Landing, PayloadHaving {

    override var payload = "BEAM and some Cube Sats"

    override fun landOn(on: LandingSiteHaving): String {
        return "Landed on ${on.landingSite} at April 8, 2016 20:52 UTC"
    }
}

val crs8 = SpaceXCRS8()
val barge = OfCourseIStillLoveYouBarge()
val spaceStation = InternationalSpaceStation()

spaceStation.fetchPayload(crs8)
crs8.landOn(barge)

🔩 The Dependency Inversion Principle

Depend on abstractions, not on concretions. (read more)

Example:

interface CoffeeMachine {
    fun brew(coffee:Coffee)
}

interface Coffee

class Arabica : Coffee


class Rabusta : Coffee

class BrewMachine : CoffeeMachine {
    override fun brew(coffee: Coffee) {
        println("Brew: $coffee")
    }
}

val brewMachine = BrewMachine()
brewMachine.brew(Arabica())
brewMachine.brew(Rabusta())

Info

📖 Descriptions from: ochococo/OOD-Principles-In-Swift Thank's

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].