-2

Introduction Components are an important building block of software. In terms of software architecture, there are a lot of principles regarding components that should be adhered to (high cohesion, low coupling, no cycles etc.).

Problem I am struggling with the transfer to C#. In C#, there are different levels which could represent components: projects in a solution, namespaces in a project, sub-namespaces in a namespace, classes in a sub-namespace.

Example E.g. when determining dependency cycles between components, one should know the components. Is it enough to avoid cycles between projects of a solution or do we need to avoid cycles between namespaces in a project etc.?

Question What is a reasonable level to consider when talking about components in C#?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Aug 3 at 0:35

1 Answer 1

3

A "component" in C# means the same thing as it does in other languages. A component is just a way to logically divide the functionality of an application into discrete units. There is no commonly accepted dividing line. Wikipedia has a good introduction to the topic, but you seem to already understand the concept. There is no special definition for a component in C# compared to any other language.

I imagine you can talk about components in C# the same way as you would in Java, C++, or any other object-oriented language. Even across programming paradigms, any cohesive set of behavior can be considered a component in a general sense regardless of how it is structured (in classes, functions, namespaces, etc).

Exceptions to this general rule can happen if a library or framework uses the term "component" and provides some additional context. For example, the Angular framework uses the term "component" to mean a TypeScript class which is used to render some HTML on a page. This does not suddenly change the general meaning of component. It becomes a meaningful concept in a particular framework. In this case, Angular has documentation to clarify what they mean by "component" and places boundaries on what it means specific to the framework.

I'm not aware of any rule for C# the language, but when the conversation includes a particular library, NuGet package, or framework, the term "component" can take on a more specific meaning. But that specific meaning is usually idiomatic to a library or framework where some documentation or naming convention exists to clarify the meaning.

Within C#, we have a Component class and an IComponent interface. The documentation provides some clarification:

(Component) Provides the base implementation for the IComponent interface and enables object sharing between applications.

Component, here, is constrained to sharing objects between applications. This is something specific to the .NET framework and isn't necessarily generalizable to other languages.

3
  • Thank you. I understand "any cohesive set of behavior can be considered a component" that there are usually probably multiple levels of components at the same time: different projects in a solution can be components, within a project different namespaces can be sub-components within the project-component etc.?
    – dn1h
    Commented Aug 3 at 5:15
  • 1
    @dn1h Words like 'component' are usually only defined in more concrete and specific terms by specific projects/teams, rather than having multiple different definitions all at once. For example, a UI team may consider a 'component' to be synonymous with a UI control. A team who uses docker containers might use it to refer to a service/daemon running inside a container. It's not that any of the definitions are right or wrong, it's more that (like most English language words) it just depends upon context and on the people using the word, as the word itself has a very loose definition. Commented Aug 3 at 14:30
  • 2
    And more to @BenCottrell's point, "component" can be defined in a general sense (e.g. "software component") or in a specific sense within some context (an Angular Component). Context is important here. Commented Aug 3 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.