12-05-2016 03:13 AM
Hello Everyone,
I need litter suggestion about Object Oriented Programming in Producer Consumer design pattern.
I have One MAIN program and Other 7 module that controlled (mean sending message or command by queue to module) by MAIN program and it has producer consumer design pattern.Now i want to convert this application into OOP but my doubt is if I will convert in OOP then each case in consumer loop is become a class(Command pattern).In such case I have more than 100-200 class in entire application.
Is it good idea to have such huge number of class in application? or i misunderstand something?
Looking forward to your suggestion.Thanks
Solved! Go to Solution.
12-05-2016 02:34 PM
100-200 does sound like a lot, though you did say 7 controllers, so you are talking 20+ concrete commands per controller? That seems like a lot of cases for your Receiver to be handling. Was your producer consumer similarly complex in number of cases? Also, could any of those classes be combined with appropriate data/logic in a class?
Just trying to understand how the scope of your application could lead to this.
12-06-2016 01:14 AM
Each controller have approx.15-20 cases in consumer loop , only one or two controller have 20-30 cases.
12-06-2016 02:14 PM
I don't think it's intrinsically bad to have that many classes if your application is complex enough to where that is what it takes to encapsulate it. If some of your cases could be combined into one concrete command with some internal data based logic you could probably reduce it.
The command pattern does generate way more classes than other approaches though. When I've played with command pattern I found lots of classes for simple tasks was the trade off for encapsulating every method in an object and I found other examples of complaints about the same thing outside LabVIEW (eg. http://stackoverflow.com/questions/4908458/command-pattern-leading-to-class-explosion).
12-06-2016 02:17 PM
I found several places suggesting that a chain of responsibility pattern might help with distributing your commands to your various handlers, but I don't think that is going to help reduce the number of classes here.
12-07-2016 08:20 AM
Yes,Let's I will try to make such logic that combine various cased and reduced number of class.
12-07-2016 03:02 PM
If you want to start using OOP you don't have to use the command pattern because your right you do end up with a lot of classes and unfortunately the LabVIEW IDE has a bad reputation for handling lots of classes gracefully.
I regularly use OOP and create classes for items within the modules but still use a standard QMH template for the module itself.
(Just my 2c, if you actually want to use the command pattern go for it, but don't feel you have to)