https://kotlinlang.org logo
#san-diego
Title
# san-diego
r

Rene

03/05/2024, 4:44 PM
based on separate concerns, on each Membership (handled as an Interface Product which has all methods related) I implemented the Factory pattern to the VIP Membership class (Product A) that must applied to all Membership types (using an abstract MembershipFactory class). Then I needed to instantiate a Factory for each membership type (VipMembershipFactory) and I called to the create method to get the Membership, Does it seems cleaner and readable this approach?
interface Membership{ fun benefits() }
abstract class FactoryMembership() { abstract fun create() : Membership }
class VipMembership() : Membership { override fun benefits(){ println("your benefits") }}
class VipMembershipFactory : FactoryMembership() { override fun create() = VipMembership() }
client code
val vipFactory : MembershipFactory = VipMembershipFactory()
val vipMembership : Membership = vipFactory.create()