Pattern to use for different Stages in a software

I am developing a software for a laboratory to test some devices. To test each device there are multi subtests which should be done to reach to the final result.To perform a complete test, the software must pass Stage1 then automatically goes to Stage2 then Stage3 and so on until the whole test is finished. meanwhile the user can select to just have the Stage3 or Stage2 or any other Stages independently to be performed (which she selects that at runtime).
this is the thing I have done so far:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class IronTestWorkFlow:ITestWorkFlow
{
private readonly List<ITestStages> _testStageses;
public IronTestWorkFlow(List<ITestStages> testStageses )
{
if (testStageses == null)
{
throw new ArgumentNullException("testStageses");
}
_testStageses = testStageses;
}
}
</code>
<code>public class IronTestWorkFlow:ITestWorkFlow { private readonly List<ITestStages> _testStageses; public IronTestWorkFlow(List<ITestStages> testStageses ) { if (testStageses == null) { throw new ArgumentNullException("testStageses"); } _testStageses = testStageses; } } </code>
public class IronTestWorkFlow:ITestWorkFlow
    {
        private readonly List<ITestStages> _testStageses;

        public IronTestWorkFlow(List<ITestStages> testStageses )
        {
            if (testStageses == null)
            {
                throw new ArgumentNullException("testStageses");
            }
            _testStageses = testStageses;
        }
    }

I am useing a DI container. But I don’t know how to change the list of Stages in ITestWorkFlow at runtime.

Questions:

1- Am I designing this right?

2- If yes which pattern shall I follow to obey the principles and change the stages at runtime? and how can I do that?

Things are Bass-Akwards

The technical term for this is inversion of control.

Your IronTestWorkFlow constructor:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> public IronTestWorkFlow(List<ITestStages> testStageses )
</code>
<code> public IronTestWorkFlow(List<ITestStages> testStageses ) </code>
 public IronTestWorkFlow(List<ITestStages> testStageses )

How did you know what stages to build before you knew what kind of Workflow you were building? You don’t, which is why you’re in this quandary I think. Premature injectulation.

Factory Pattern instead of DI Container

Let’s use the Factory Pattern – put the Workflow and Stage building into WorkflowFactory and StageFactory classes respectively. The user will select an iron test for example so the IronTestWorkFlowFactory is called which in turn calls the StageFactory to build the stages it needs. Thus we have the context needed to build the right stages.

I take it from the problem description that higher level code should be able to call on a WorkFlowFactory or a StageFactory as desired, depending on how granular or customized of a thing the user wants. So make sure any dependencies between the factories is done via parameters; that’s basic Dependency Injection. A DI container is not necessarily required to do dependency injection.

Stay object oriented

Think long and hard about the things you’re manipulating: Stage, WorkFlow, other? Focus on the core “data structures” first.

Beware too much focus on high level abstract “framework” without some meat designed into core classes, which results in these classes badly un-encapsulated with numerous violations of single responsibility principle further resulting in undesirable and painful coupling.

For example I wonder what a Workflow – an ordered list of stages – looks like and what fundamental operations are done with them. I wonder if there is some business rules that define order independent of the order in which they just happen to be instantiated? If so then implementing IComparable can make a profound difference. Been there, done that.

This problem doesn’t necessarily need to be solved with design patterns but, to answer your question, you could arrange the tests you need using a simple list or use a composite pattern if you want to make a little more complicated. You could then use different strategies to iterate over the list of tests, each strategy reacting to success or failure appropriately.

This might not be your final solution, but it’s food for thought…

2

You can use a Mediator pattern. You would have a master list of all available tests in the master workflow. A user won’t talk to this workflow directly, but instead to the Mediator. The Mediator will keep track of which tasks are actually selected (in its own list), and expose those to the user.

1

It would appear there are a myriad of patterns that may be employed here. One to consider is the State pattern if you must transition from one test to another automatically (each State must know how to transition its context to the next state, in your case, these states would be your specific lab tests if I understood the problem correctly)

or even some variant of Chain of Responsibility might be useful.

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