Если вы думаете о Всемирной паутине, легко представить ее как единую программную систему. Как только вы это сделаете, вы поймете, что это самая большая система программного обеспечения, которую когда-либо создавал мир — возможно, на сотни порядков. Он содержит триллионы строк кода, сотни миллионов серверов и миллиарды клиентов, использующих тысячи различных языков программирования. Тем не менее, он работает более или менее так, как мы ожидаем, что он будет работать. Итак, что позволило людям создать такую огромную программную систему? Ответ прост: HTTP !
Протокол HTTP позволяет нам создавать идеальную инкапсуляцию. Клиенту и серверу не нужно ничего знать друг о друге, кроме URL, HTTP-глагола и параметров, которые нужно передать и ожидать в качестве вывода. Это позволяет миллиардам клиентов взаимодействовать друг с другом, не зная (почти) ничего друг о друге. Если вы сведете его к базовым компонентам, становится очевидным, что следующий рецепт для победы.
-
Волшебные строки (URL).
-
Общие и нетипизированные полезные нагрузки ( JSON ).
-
DNS- преобразование URL-адресов в физический адрес некоторого клиента / сервера.
Вам также может понравиться:
Серия HTTP (часть 1): обзор основных понятий .
Они лгали тебе!
The funny thing is that this contradicts some 60 years of software development theory, with strong typing, rigid classes, OOP, etc., where everything should be known at compile time. If anything, the Web’s success is based upon completely ignoring every single «best practice» we as software developers have taught ourselves over the last 60+ years.
The paradox is that the above recipe, can also easily be implemented internally within our own systems. Just throw away OOP, forget all about static and strong typing, and invoke your methods as «magic strings.» You’ll never again experience complexity problems, with entangled dependencies, making it impossible to create a software system above some threshold of complexity, without reducing it to a big ball of mud. Imagine the following pseudo-code:
xxxxxxxxxx
/*
* This is a method invocation, based upon a "magic string".
* The parameters to our invocation is basically a graph object
* Think "JSON" here ...
*/
"foo.bar"({someUntypedGraphObjectGoesHere})
All of a sudden, there are no dependencies between the place in your code where you are invoking a function and the place where you have implemented the function. There are no strong types transferred between the caller and the method, and nothing is shared, except a mutual agreement of what data to provide and return. Your dependency graph has been effectively reduced to ZERO! No OO, no problems!
All of a sudden, an in-process method invocation has been completely decoupled from the underlying method, and you have all the scalability features internally within your process, as you have with the HTTP standard. This results in software systems with the same amount of complexity as the Web, without experiencing scalability problems that normally occur long before you reach this amount of complexity.
Isn’t This SOA?
No. Service Oriented Architecture is based upon having multiple servers, and/or processes. This is completely in-process. There’s no need to fiddle with socket connections, server configurations, or anything that creates added complexity. In fact the «DNS» of the above «Magic string method invocations» is a simple dictionary, resembling the following:
xxxxxxxxxx
Dictionary<string, Type> _dns;
Then, you look up a type from your «DNS,» like the following, and instantiate an instance of an interface, making it possible to invoke your loosely coupled function.
xxxxxxxxxx
var type = _dns["magic-string"];
var instance = services.GetService(type) as IMagicStringType;
instance.InvokeLooselyCoupledMethod(/* ...arguments... */);
At this point, all you need is a Node class, capable of passing around arguments — basically the equivalent of JSON for C#, something resembling the following:
xxxxxxxxxx
class Node
{
public string Name { get; set; }
public object Value { get; set; }
IEnumerable<Node> Children { get; set; }
}
Your dictionary becomes your «DNS,» the magic string becomes your «URL,» and the Node class becomes your «JSON.» This allows for completely independent modules to interact with each other in the same way that the HTTP standard allows completely independent servers to interact with each other, completely eliminating every single dependency between your two components in the process. And as to the speed of this? Well, it’s a simple dictionary lookup and an IoC dependency injection invocation. It’s more or less the same speed as anything you’re already doing in your .NET applications.