Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Created February 7, 2021 23:51
Show Gist options
  • Save deanwampler/ef5587caa4ff8c2ceb3ffdd444a84f32 to your computer and use it in GitHub Desktop.
Save deanwampler/ef5587caa4ff8c2ceb3ffdd444a84f32 to your computer and use it in GitHub Desktop.
// Adapted from Programming Scala, Third Edition code repo:
// https://github.com/deanwampler/programming-scala-book-code-examples/blob/master/src/script/scala/progscala3/basicoop/Exports.scala
import java.net.URL
case class UserName(value: String):
assert(value.length > 0)
case class Password(value: String):
assert(value.length > 0)
trait Authenticate:
final def apply(
username: UserName, password: Password): Boolean =
authenticated = auth(username, password)
authenticated
def isAuthenticated: Boolean = authenticated
private var authenticated = false
protected def auth(username: UserName, password: Password): Boolean
class DirectoryAuthenticate(location: URL) extends Authenticate:
protected def auth(username: UserName, password: Password): Boolean = true
object Service:
private val dirAuthenticate =
DirectoryAuthenticate(URL("https://directory.wtf"))
export dirAuthenticate.{apply => authenticate, isAuthenticated}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment