Is this a pattern? If so, which one? (Contexts, Requests and Responses) [closed]

In most of my code nowadays, I adapted to an approach which I think I read in the context of “Clean Code”. It was some years ago and I cannot find the source again, so I would like to know what the name of this pattern really is (and if it’s even a pattern).

The approach is so simple, yet powerful that I am baffled as to how hard it is to find sources on this, but that might just be lack of proper search words.

The approach is, in order to write unit-testable code, to decouple the function and presentation of an application (duh) in such a way, that the two parts actually communicate via an interface which I always describe as “HTTP-Like”.

That is, the functions your code can do are one project, and the display etc. are another project. The only communication between the two is done by using Context classes, which accept a Request and return a Response for anything your code can do.

So, e.g. if your code translates a sentence, you’d have a TranslationContext, along with the TranslationRequest (which has a property text) and the TranslationResponse (with a property text that includes the translated text).

The Context class is the only interface from your actual application code to the “outside”, whereas the “view” is also seen as the outside.

From the presentation side, you’ call

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>TranslationContext ctx = new TranslationContext(interfacedDbOrTextfile);
TranslationRequest req = new TranslationRequest("hallo welt");
TranslationResponse resp = ctx.Process(req);
Console.Write(resp.Text); // "hello world"
</code>
<code>TranslationContext ctx = new TranslationContext(interfacedDbOrTextfile); TranslationRequest req = new TranslationRequest("hallo welt"); TranslationResponse resp = ctx.Process(req); Console.Write(resp.Text); // "hello world" </code>
TranslationContext ctx = new TranslationContext(interfacedDbOrTextfile);
TranslationRequest req = new TranslationRequest("hallo welt");
TranslationResponse resp = ctx.Process(req);
Console.Write(resp.Text); // "hello world"

Additionally, any data sources (DB, Text files, etc) must be interfaced and decoupled when passed to the core, so you can always replace them with UnitTestable things like in-memory strings instead of textfiles or arraylists instead of database rows.

Is what I am describing just the application of known patterns in a way that I cannot see? Or is it a pattern which was not described yet? Or am I just using different words for things that already exist?

6

The Context Object is a pattern used in a number of places, including J2EE, ASP.NET MVC and Entity Framework. It is used “to encapsulate state in a protocol-independent way to be shared throughout your application.”

Context Object is a controversial pattern. Although it can be thought of as a means of Inversion of Control or Dependency Injection, it’s really more like a convenient way of passing the working environment around (akin to a “god object.”) Context objects can be difficult to mock, therefore testability of the code that uses them is negatively impacted.

Further Reading
Context Object
Passing around ginormous context objects
Mocking HttpContext

Requests and responses are just message passing.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật