hyperoslo / AsyncWall

hyper.no
Other
10 stars 0 forks source link

Model protocols #71

Closed vadymmarkov closed 9 years ago

vadymmarkov commented 9 years ago

Was playing with this a bit and the first thing I've tried was a protocol like this:

protocol PostConvertible {
  var post: Post { get }
}

Such kind of protocols could be used for every model we have, but I don't really like that Post knows about it:

public class Post: NSObject {

  public var author: UserConvertible?
  public var group: GroupConvertible?
  public var parent: PostConvertible?
  public var comments = [PostConvertible]()
  ...

Also with this approach we should use post.post, user.user everywhere and it looks not very nifty as for me.

Another option is to convert current Wall models to protocols, but if our model that implements this protocol doesn't need to have title for example, we have to add it anyway, like:

class Post: Wall.Post {
  ...
  public var title: String?
  ...
}

@zenangst @RamonGilabert Any thoughts?

zenangst commented 9 years ago

@vadymmarkov @RamonGilabert I believe that protocols is the way to go, even if that might be a bit odd in terms of lack of optionals. Just my 50 cents.

RamonGilabert commented 9 years ago

I feel right now it's a bit strange to have (if we go for the first option) user.user, or post.post, although I feel that the second way it's not that bad. Swift is protocol oriented, and as yesterday discussed with Chris, we're going to use Swift 2.0 in this project, apparently, I think is the way to go...

vadymmarkov commented 9 years ago

@zenangst @RamonGilabert Ok, then we'll go with the second way. What do you think is the best name for protocols, something like PostConvertible? Don't want to name it just Post, it's not protocol naming style and could cause conflicts with class names in the actual project.

zenangst commented 9 years ago

@vadymmarkov Postable, Feedable. I kinda like the -able suffix. We see if quiet a lot in Swift right, Comparable, Equatable and so on?

Am I right? @RamonGilabert

RamonGilabert commented 9 years ago

@vadymmarkov was actually suggesting an able suffix, but I like more the one word naming for Models!

vadymmarkov commented 9 years ago

@zenangst @RamonGilabert It works for Post, but what about other classes? Userable, Attachable, Groupable, Imagable, Videoable :smile: ?

zenangst commented 9 years ago

@vadymmarkov @RamonGilabert Some of them are actually in the English dictionary :sunglasses: I think it works.

Attachable : to attach a photograph to an application with a staple. Groupable : able to be grouped

RamonGilabert commented 9 years ago

Userable is horrible in my opinion though... And Imagable and Videoable also horrible... What do you think?

zenangst commented 9 years ago

@RamonGilabert

Imageable : Capable of being imaged.

RamonGilabert commented 9 years ago

@zenangst let's do it then, but userable also?

zenangst commented 9 years ago

Could you go for something like;

Attachment -> Attachable Group -> Groupable Image -> Displayable Video -> Playable User -> Profileable

@vadymmarkov @RamonGilabert thoughts?

RamonGilabert commented 9 years ago

Getting nicer over here! :)

vadymmarkov commented 9 years ago

Looks good now!