{"id":14676,"date":"2016-05-31T10:13:49","date_gmt":"2016-05-31T14:13:49","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14676"},"modified":"2016-05-31T10:13:49","modified_gmt":"2016-05-31T14:13:49","slug":"mocking-dependencies-with-generics","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/05\/31\/mocking-dependencies-with-generics\/","title":{"rendered":"Mocking Dependencies With Generics"},"content":{"rendered":"<p><a href=\"http:\/\/elm4ward.github.io\/swift\/generics\/mocking\/dependency\/injection\/2016\/05\/21\/generic-dependency-mocking.html\">Elmar Kretzer<\/a> (via <a href=\"http:\/\/andybargh.com\">Andy Bargh<\/a>):<\/p>\n<blockquote cite=\"http:\/\/elm4ward.github.io\/swift\/generics\/mocking\/dependency\/injection\/2016\/05\/21\/generic-dependency-mocking.html\"><p>You can inject code dependencies in a transparent way by using generics and <code>typealias<\/code>.<\/p><p>[&#8230;]<\/p><p>Those dependencies are loosely coupled, but in my opinion they belong together in a semantic way.<\/p><p>[&#8230;]<\/p><p>We end up with:<\/p><ul><li>a generic <code>ModelFor<\/code> taking a type conforming to <code>Environment<\/code><\/li><li>a typealias <code>Model<\/code> representing <code>ModelFor&lt;RealWorld&gt;<\/code><\/li><li><strong>no<\/strong> code necessary to manage the dependencies with properties or whatever<\/li><\/ul><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Elmar Kretzer (via Andy Bargh): You can inject code dependencies in a transparent way by using generics and typealias.[&#8230;]Those dependencies are loosely coupled, but in my opinion they belong together in a semantic way.[&#8230;]We end up with:a generic ModelFor taking a type conforming to Environmenta typealias Model representing ModelFor&lt;RealWorld&gt;no code necessary to manage the dependencies [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[27,71,901,268],"class_list":["post-14676","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-craft","tag-programming","tag-swift-programming-language","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14676"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14676\/revisions"}],"predecessor-version":[{"id":14677,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14676\/revisions\/14677"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}