Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - What Interfaces are in UML Component Diagrams

Tags:

c

uml

components

What is exactly an interface in a Component diagram in C?

I am an embedded systems tester understanding software development architecture. I have seen Component diagrams of the project I perform Black Box testing. I have seen that components are represented by blocks that joins with "sockets" and "lollipos". I know that those are interfaces, and components provide and request interfaces. I have read different articles but i do not find a practical example of it. Are they functions and variables, and the component that request such interface calls it and the provider has the definition of the function?

like image 759
PySerial Killer Avatar asked Dec 08 '17 22:12

PySerial Killer


People also ask

WHAT IS interface in UML component diagram?

Artifacts represent physical implementation units, such as executable files, libraries, software components, documents, and databases. In UML modeling, interfaces are model elements that define sets of operations that other model elements, such as classes, or components must implement.

What is required interface in component diagram?

Interfaces in component diagrams show how components are wired together and interact with each other. The assembly connector allows linking the component's required interface (represented with a semi-circle and a solid line) with the provided interface (represented with a circle and solid line) of another component.

How components are related with interfaces in UML?

A component is a single unit of the system, which is replaceable and executable. The implementation details of a component are hidden, and it necessitates an interface to execute a function. It is like a black box whose behavior is explained by the provided and required interfaces.


3 Answers

What is exactly an interface in a Component diagram in C? [...] I have read different articles but i do not find a practical example of it. [...]

I believe there are cases where it could be low-level interfaces (for a C module) or something higher level, such as a REST API or communications protocol. I think the general idea is that an interface is something published, which allows implementations to be swapped in and out.

Here's an example used in Craig Larman's Applying UML and Patterns book, which is concrete:

PlantUML component diagram with two components

The MyApp system requires two components, one for the messaging, one for the database (DB). The interface of each is standard (in this example), namely JMS and SQL respectively.

In your case with C, the interfaces are probably defined in one or more .h files for each component (which could be one or more .c files, again there is some flexibility on what is a component). They likely are not as "standard" as JMS, SQL, etc., but if you're doing testing, you should be able to test on both sides of an interface.

like image 95
Fuhrmanator Avatar answered Oct 20 '22 17:10

Fuhrmanator


Definition of a component according to the UML standard:

A Component represents a modular part of a system that encapsulates its contents and whose manifestation is replaceable within its environment.

A Component is a self-contained unit that encapsulates the state and behavior (...). A Component specifies a formal contract of the services that it provides to its clients and those that it requires from other Components or services in the system in terms of its provided and required Interfaces.

A Component is a substitutable unit that can be replaced at design time or run-time by a Component that offers equivalent functionality based on compatibility of its Interfaces. (...)

A component defined by its API

In C a component can be a set of compilation units that define functions and global variables that are visible to other compilation units, and that may require the existence of functions or global variables in other components:

  • the set of global variables and functions implemented by the component (and available for others) is the interface that is offered.
  • the set of extern global variables and functions that are expected by the component to be defined elsewhere is the required interface.

A component defined by a structure

In C you can also develop using an object oriented style. Of course, it's not so nice and convenient as C++. But it allows to develop interchangeable components.

The trick is to use a structure that defines data members or pointers to data members (state) and function pointers obeying certain signatures (behavior). In this case, the definition of the structure defines the interface provided by the component.

Microsoft is for example using such an approach for its COM technology

A component defined by its system interface

A C component doesn't need to be a part of a larger programme and offer a source code or an object code interface. It can be itself an independent programme, that offers an interface at runtime using OS features, such as a network protocols (listening to sockets, or implementing HTTP or other network protocols), remote function calls or other IPC techniques (e.g. shared memory, mutexes, etc...).

The interface is a contract

As the examples above have shown, the interface is not limited to a specific language feature. An interface is a contract about what is provided and what is expected to communicate with the component.

like image 35
Christophe Avatar answered Oct 20 '22 16:10

Christophe


Basically an interface is a declaration of attributes and operations someone might offer or need. A class can implement an interface which means it must implement the operations and have the attributes accessible. Now a component is something that is composed of 1..n classes and interface can be made visible outside the component. So finally a component can show a number of different interfaces which a number of its internal classes offer to the outer world.

Regarding sockets and lollipops: The lollipops represent provided interfaces (classes that have implemented it). The sockets represent required interfaces. That is there must be a counterpart somewhere to connect which offers an implementation of the interface.

like image 1
qwerty_so Avatar answered Oct 20 '22 17:10

qwerty_so