Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added builder pattern to BKTConfig #13

Merged
merged 16 commits into from
Jul 3, 2023

Conversation

duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented Jun 29, 2023

Changes

  • For external use: BKTConfig could only init using BKTConfig.Builder.
  • Remove sdk_version from BKTConfig.Builder. The SDK's consumer no longer needs to set the SDK version.
  • Update E2E test with new values
  • Fixed tvOS example is outdated and not buildable

@@ -1,6 +1,6 @@
import UIKit

public struct BKTConfig {
public class BKTConfig {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BKConfig

  • It has a property named logger which could be an instance of a class.
    So It should be a class. Because a Struct's property should be only basic data_type, not a class.

  • Next, we put a Builder class as an inner class here and we want to use the Swift convenience init to reuse the base init method of BKConfig, and Builder will not know too much about how to init the outer class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, Builder patterns are not common in iOS development. Still, for SDKs, this pattern is helpful when we want to add or edit some configuration without breaking changes, especially for SDKs working as a proxy such as Flutter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by remove the breaking changes

logger: builder.logger)
}

public class Builder {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builder as an inner class.
The benefit here, every time the consumer wants to create a BKConfig by entering BKConfig.
The IDE will show a suggestion to use the Builder

Screenshot 2023-07-01 at 15 34 08

@duyhungtnn
Copy link
Collaborator Author

Hi @cre8ivejp Could you please take a look on this changes

@duyhungtnn duyhungtnn marked this pull request as ready for review July 1, 2023 11:43
@@ -1,6 +1,6 @@
import UIKit

public struct BKTConfig {
public class BKTConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, Builder patterns are not common in iOS development. Still, for SDKs, this pattern is helpful when we want to add or edit some configuration without breaking changes, especially for SDKs working as a proxy such as Flutter.

/**
* Create a new builder with your API key.
*/
public init(apiKey: String) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if we don't pass the apiKey.
Usually, for builder patterns, it passes the required parameters in the init, and the optional settings are passed via .with. Or, we pass nothing in the init.

Since you have already added the .with for the apiKey, let's remove it from the init.
https://github.com/bucketeer-io/ios-client-sdk/pull/13/files#diff-a01b127e0bdeebe208c5ce7cac0dfd53041a03921bc362c81bdb3954f333d81eR100-R103

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @cre8ivejp the builder patterns are not common in ObjectC.
But it is popular with Swift.
The idea when init with apiKey is: it is an indicator for something so important and should be set by default, it should not an optional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.
My previous message mentioned passing the required configuration. But, If we are going to pass the apiKey, we should also pass the apiEndpoint and the appVersion. But, to keep the consistency, we should do it as Android.

https://github.com/bucketeer-io/android-client-sdk/blob/main/bucketeer/src/main/kotlin/io/bucketeer/sdk/android/BKTConfig.kt#L28

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by remove init with apikey

@duyhungtnn duyhungtnn marked this pull request as draft July 3, 2023 08:09

final class BKTConfigTests: XCTestCase {

func testCreateConfig() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will add it.
In the current test, if the user missing something, the BKTConfig will be nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added. Please continue review @cre8ivejp

@duyhungtnn duyhungtnn marked this pull request as ready for review July 3, 2023 10:53
Copy link
Member

@cre8ivejp cre8ivejp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@cre8ivejp cre8ivejp changed the title feat: create BKTConfig Builder chore: added builder pattern to BKTConfig Jul 3, 2023
@cre8ivejp cre8ivejp merged commit 48dff87 into bucketeer-io:main Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants