Can the port of a UML component only be a singleton?

I am working on a software assignment where the design is component based. The components have ports which provide interfaces.

My professor argues that the Port class which is exposed by each component should be a Singleton, as the port must be the only way to interact with the component. As I see it, multiple instances don’t interfere with the requirement that the port must be the single interaction point.

Is as singleton the right way to implement a Port to the component?

To give an example:
The assignment is a model of an airplane and an airport. The components are different parts of an airplane and the airport. As it is a group assignment, different students have to implement different components.
This is the UML diagram of the different components of the airport: Airport Components

The interfaces are implemented in a class named Port, which is an inner class to the actual implementation. The outer class has a public field port and is a singleton. The different components interact by loading the Jar-File and accessing the Port instance via reflection.

13

Can the port of a UML component only be a singleton?

According to https://www.uml-diagrams.org/port.html UML does have notation to indicate multiple instances of a port, as well as multiple interfaces to a port.

Multiplicity of a port (if any) is shown after the port name in square brackets. Both name and multiplicity of port are optional.

UML Port with multiplicity - Library Services class has 1 to 6 searchPort ports.

Library Services class has 1 to 6 searchPort ports.

In UML diagrams, you will most likely see the majority of diagrams with one port. From a logical perspective, this is correct. From an implementation perspective, it shouldn’t matter.

Logically, you are connecting to one instance of a component that exposes functionality on the port. In real life there may be multiple instances of the same component and you only care about the interaction with one of them.

4

Singelton as a concept

Yes, since the port is a limited resource there should be only one object at runtime (a singleton) interacting with it. It should handle concurrent access of other components to that port.

So your application should create only one instance of the “PortHandler”.

Singelton as Code pattern

Often the logical singelton as described above is realized in code using the Singelton Pattern (private constructor and static accessor method)

This should be avoided.

The reason is that this static access makes your code tight coupled and therefore hard to reuse and in consequence hard to test. Also this “code supported singeltons” are merely a global variables which are known being evil almost since the beginning of programming…

e.g.: if you want to unittest your code interacting with the “PortHandler” you might want to replace the real “PortHandler” with a test double which you can programmatically configure to produce well defined data for your tested code.

If your Code under test gets the “PortHandler” via the static accessor method of the Singelton Pattern it is hard to replace.

If you pass the “PortHandler” in via dependency injection (using a DI framework by any chance) replacing it for testing is easy…

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