Writing a User object in Swift, though my question relates to any strongly typed language. A User can have a bunch of links (FacebookProfile, InstagramProfile, etc). A few questions around this.
- Is it good practice to wrap links in its own object?
struct User { var firstName: string var lastName: string var email: string var links: Links }
struct Links { var facebook: string var instagram: string var twitter: string }
Or should they be loose? I know technically both ways are fine, but wondering if there is a recommended approach, in general–especially for readability.
struct User { var firstName: string var lastName: string var email: string var facebookLink: string var twitterLink: string var instagramLink: string }
-
In a scenario like this, should links be a collection/list? I figured it should not be a list because there is a fixed number of link options available, and not a growing number. Is my thinking right?
-
Is it good practice to place my networking methods inside the User object, like getUsers, getUser, updateUser?
I know these could be subjective, but I am trying to understand what the best practice around similar situations is. Would appreciate any pointers.