Not sure what design pattern works better in my case

Currently I have a large ontology like this:
enter image description here

There are different categories of variants and each can be somatic or germline.
There are more common behaviours between same variants, like somatic CNVs and germline CNVs have more common behaviours due to the fact that they are both CNVs. But there also are a few behaviours common between small somatic and somatic fusions due to them being somatic (this design doesn’t account for that kind on reuse).

So I’m thinking of changing it to something else, a strategy pattern with a factory, like this:
enter image description here

But this runs into the issue that I have too many behaviours and they are quite specific to a class of variant. Example of behaviours:

  • calculate_position()
  • calculate_gene_location()
  • calculate_log2foldchange()

All these do something different depending on variant type. And they are quite short functions. So I’ll end up creating a lot of small behaviour classes and end up with a more extensive ontology.

Not all variants have the same behaviours: some have a protein_prediction() or split_reads(). At the end of the day I want to be able to get 8 classes with the behaviours that I need.

Any ideas of a better way to organise my code?

2

Are you sure you need design patterns at all ?

Sorry for this provocative counter-question. But all too often, we see questions looking at design patterns, like they were a catalogue of raw material for a proper design.

Design patterns are only predigested solution for common design issues. Instead of looking for patterns that could help to solve problems that you have not yet, first clarify what you want to design first. Use patterns only if there are some helpful match with your own intents.

What is your intent ?

Unfortunately, I’m not biologist and have only little clue about genome and mutations. With google’s help, I learnt a little more on somatic and germline cells, stomatic and gemline mutations, fusions and diruptive mutations and CNV. But still, I’m not able to give specific advice about what to inherit and what to compose.

Your narrative suggests that the challenge is to combine the behaviors and master the combinatorial explosions.

It is however not clear how strongly the behavior is related to the kind of variant, how much behavior can be shared across several variants, and how much a separately defined behavior has to know about the variant.

At least three approaches could be considered:

  • inheritance with specific overrides for specific variants. This might result in a deeply nested class hierarchy and some redundant code, looking at redundant characteristics in the ontology. Here, the decorator pattern could help to add behavior that is not common to all kind of variants. The advantage is that behaviors have full access to all the variant’s attributes.
  • composition, delegating some behavior to specific component. If several components define together the behavior, multiple dispatch could be considered. This works very well if all atributes of the behavior can be migrated to the component. If behavior is only influenced marginally by some components, the template method pattern combined with delegation could be a better option.
  • composing behavior. The strategy pattern belongs to this category. If works well if parts of behavior can be encapsulated. You may also use the entity component systems approach. It is popular in the game industry, since it allows to keep class hierarchies flat and avoid combinatorial explosion.
  • any combination thereof.

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