N
N
Nick_Field2014-06-19 17:55:17
C++ / C#
Nick_Field, 2014-06-19 17:55:17

What design pattern to choose for a list of objects of different types?

There are three types of objects: 1
) A slot that displays information
2) A free slot
3) A locked slot
this type? I write in C#. So far, only a solution with a type check is spinning in my head. Maybe there is some design pattern that allows you to solve this problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
CAMOKPYT, 2014-06-19
@Nick_Field

Implement the same interface for all three types of objects, no patterns

A
anyd3v, 2014-06-19
@anyd3v

As I understand it, you need pattern matching, I'm not strong in C # (the last time I used it was in 2010)
Look here for some thoughts on this
codebetter.com/matthewpodwysocki/2008/09/16/functi...
stackoverflow.com /questions/6031555/implementing-p...

G
gleb_kudr, 2014-06-20
@gleb_kudr

Here are the options:
1. Inheritance from one class
2. Implementation of one interface.
3. A special wrapper class that can take elements of your zoo as input and convert them into a standard interface to the collection.
And I don't really understand why you don't like typecasting to access unique fields. This is absolutely standard practice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question