Forum Discussion

Jack1590's avatar
Jack1590
Reel Rookie
5 years ago

Builder pattern in brightscript

Hi

i'm planing to create a library which received a config to enable or disable features. this config object has several fields so I wonder if it is useful to have a builder pattern as scenegraph objects have default values for its fields maybe it's not needed to have a builder

for instance 

Builder Implementation

configBuilder = createObject("roSGNode", "ConfigBuilder")
configBuilder.callFunc("withAppId", "rew4324123")
configBuilder.callFunc("withAds", true)

config = configBuilder.callFunc("build")

myLib = createObject("roSGNode", "MyLib")
myLib.callFunc("start", config)

Plain Object Implementation

config = createObject("roSGNode", "Config")
config.appId = "rew4324123"
config.adsEnabled = true

myLib = createObject("roSGNode", "MyLib")
myLib.callFunc("start", config)

 

Which approach do you think it's better for br?

  • atc98092's avatar
    atc98092
    Community Streaming Expert

    You need to post this on the developer's side of the forum. This area is for end users, and very few people here will have any idea what you're talking about. 🙂