Blog Infos
Author
Published
Topics
Published
Topics
Are you sure “reducing coupling” is what you‘re after?

Photo by Theo Crazzolara https://unsplash.com/photos/k8mRwVA4MpA

The good
Polymorphism
interface Message {
val timestamp: DateTime
}
class TextMessage(
val text: String,
override val timestamp: DateTime
) : Message
class ImgMessage(
val imgUri: URI,
override val timestamp: DateTime
) : Message
Multiple inheritance
interface ToastShowable {
fun showToast(context: Context, text: String) = ...
}
class MainActivity : ComponentActivity(), ToastShowable {
override fun onCreate(savedInstanceState: Bundle?) {
//...
showToast(this, "Le toast")
}
}

You can do something similar on iOS by leveraging protocol extensions.

protocol Shakeable {
func shake()
}
extension Shakeable where Self: UIView {
func shake() {
UIView.animate(...
}
}
Boundaries between layers

Simplified clean architecture schema

Job Offers

Job Offers


    Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Senior Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Mobile Engineer

    OLX Group
    Remote, Portugal, Spain, Romania, Poland
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

,

At long last we have Kotlin first at Meta!

Android started to support Kotlin 5 years ago and became the first-choice language three years ago. But Meta just announced Kotlin as the preferred and default language for our Android code base only 3 months…
Watch Video

At long last we have Kotlin first at Meta!

Peng Jiang & Sergei Rybalkin
Software Engineer & Kotlin
Meta

At long last we have Kotlin first at Meta!

Peng Jiang & Serge ...
Software Engineer & ...
Meta

At long last we have Kotlin first at Meta!

Peng Jiang & Ser ...
Software Engineer & Kotli ...
Meta

Jobs

Clean architecture is very widespread in mobile development, but one thing that is often misunderstood is that the data layer is outer to the domain layer. Business logic doesn’t need to know how the data is delivered, it should only define its inputs, usually via the means of a Repository interface, which can be implemented by the data layer.

 

In clean architecture, the domain layer defines Repository interface which is implemented by data layer

 

The bad
Test Doubles
protocol Grinder {
func grind(_ coffee: Coffee)
}
class GrinderMock: Grinder {
private(set) var timesUsed: Int = 0
func grind(_ coffee: Coffee) {
timesUsed += 1
}
}
class CoffeeMakerTest: XCTestCase {
func test_grinder_used_once_when_coffee_made() {
let grinder = GrinderMock()
let sut = CoffeeMaker(grinder: grinder)
sut.makeCoffee()
XCTAssertEqual(grinder.timesUsed, 1)
}
}
Callbacks
public interface OnClickListener {
void onClick(View v);
}
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//handle click
}
});

This is no longer idiomatic in Kotlin. Functions are types in Kotlin, so you can easily pass them around as variables

class ListAdapter(val itemClickListener : () -> Unit) { ...
fun interface OnClickListener { fun invoke() }
The ugly
“Because I can easily replace it with another implementation”

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
Hi, today I come to you with a quick tip on how to update…
READ MORE
blog
Automation is a key point of Software Testing once it make possible to reproduce…
READ MORE
blog
Drag and Drop reordering in Recyclerview can be achieved with ItemTouchHelper (checkout implementation reference).…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu