Allan Caine
Dec 28, 2020

I suggest that the validate function should reside in object EmailValidator. Then, the client merely calls

EmailValidator.validate("foo@foo.com")

It is also worthwhile exploring typealias.

typealias Email = String

Email.validate(): Boolean {

}

The code makes the developer's intention clear: strings which represent emails can be validated.

I believe it is valid to have an extension function to validate a String, when the string represents an email.

Your approach to use a utility object is also a valid approach too.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Allan Caine
Allan Caine

Written by Allan Caine

Senior Android Developer, TD Bank (Canada) (Opinions are my own)

Responses (1)

Write a response