-
Notifications
You must be signed in to change notification settings - Fork 1
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
The design of Common API #3
Comments
First of all, common point is posting messages. |
Yeah, and in general, these are listed on timelines. |
Also, It's necessary to decide the object-name of posted text message. (e.g. Status, Message, or Text etc.) |
I think "Message" sounds good! How do you like to call it? @mak0tia @siketyan |
But, when we want to define other messages, it will be probably a not good decision 🤔 |
Or, How about "TextMessage"? |
The message contains text is not necessarily so. How about inheritance?
|
sounds good! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
とりあえず、現状の構想でcommonプロジェクトを作成してみた
|
構想 using System.Threading.Tasks;
namespace Information
{
public interface IService { }
public interface IMessage { }
public interface IMessagePostable<T> where T : IMessage
{
Task<T> PostMessageAsync(T message);
}
}
namespace Information.Services
{
public class Twitter :
IService,
IMessagePostable<Twitter.TextMessage>,
IMessagePostable<Twitter.ReactionMessage>
{
public Task<TextMessage> PostMessageAsync(TextMessage message) => null;
public Task<ReactionMessage> PostMessageAsync(ReactionMessage message) => null;
public class TextMessage : IMessage
{
public string Content { get; set; }
}
public class ReactionMessage : IMessage
{
public ReactionType Type { get; set; }
}
public enum ReactionType { Like }
}
}
public class Program
{
public async void Main()
{
var tw = new Information.Services.Twitter();
var text = new Information.Services.Twitter.TextMessage();
text.Content = "hoge";
await tw.PostMessageAsync(text);
var reaction = new Information.Services.Twitter.ReactionMessage();
reaction.Type = Information.Services.Twitter.ReactionType.Like;
await tw.PostMessageAsync(reaction);
}
} どうだろう..
|
ReactionMessage のリアクション対象の指定ってどこでやる感じです?
|
var text = new Information.Services.Twitter.TextMessage();
text.Content = "hoge";
await tw.PostMessageAsync(text); It looks a little bit complex. |
それはそう。どのようにすれば最適だろう?
ReactionMessageのコンストラクタもしくはプロパティから設定することになりそう |
リアクションをメッセージとして扱うのは抽象化し過ぎかなあ |
案2
メソッド名がすべてのサービスで共通になるというメリットがあるが、結局パラメータとして与えるTextMessageやReactionのような「モデル」は全てのサービスで定義して使い分けないといけない。 using System.Threading.Tasks;
using static Information.Services.Twitter;
namespace Information
{
public interface IService { }
public interface IMessagePostable<T> { Task PostMessageAsync(T message); }
public interface IMessagePostable<T, TRes> { Task<TRes> PostMessageAsync(T message); }
public interface IReactionPostable<T> { Task PostReactionAsync(T reaction); }
public interface IReactionPostable<T, TRes> { Task<TRes> PostReactionAsync(T reaction); }
}
namespace Information.Services
{
public class Twitter :
IService,
IMessagePostable<TextMessage>,
IReactionPostable<Reaction>
{
public Task PostMessageAsync(TextMessage message) => null;
public Task PostReactionAsync(Reaction reaction) => null;
public class TextMessage
{
public TextMessage(string text, string inReplyToStatusId = null)
{
Text = text;
InReplyToStatusId = inReplyToStatusId;
}
public string Text { get; set; }
public string InReplyToStatusId { get; set; }
}
public class Reaction
{
public Reaction(ReactionType type, string targetMessageId)
{
Type = type;
TargetMessageId = targetMessageId;
}
public ReactionType Type { get; set; }
public string TargetMessageId { get; set; }
}
public enum ReactionType { Like }
}
}
public class Program
{
public async void Main()
{
var tw = new Information.Services.Twitter();
await tw.PostMessageAsync(new TextMessage("hoge"));
await tw.PostReactionAsync(new Reaction(ReactionType.Like, "abc"));
}
} |
Overview
From #2.
In this issue, we have a discussion about designing
Information.NET.Common
.The text was updated successfully, but these errors were encountered: