LabVIEW Development Best Practices Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

OOP into Producer Consumer

Solved!
Go to solution

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

Kuddo welcomed
CLAD-CTD
0 Kudos
Message 1 of 7
(8,991 Views)

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.

0 Kudos
Message 2 of 7
(8,957 Views)

Each controller have approx.15-20 cases in consumer loop , only one or two controller have 20-30 cases.

Kuddo welcomed
CLAD-CTD
0 Kudos
Message 3 of 7
(8,946 Views)

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).  

0 Kudos
Message 4 of 7
(8,935 Views)

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.

0 Kudos
Message 5 of 7
(8,933 Views)

Yes,Let's I will try to make such logic that combine various cased and reduced number of class.

Kuddo welcomed
CLAD-CTD
0 Kudos
Message 6 of 7
(8,918 Views)
Solution
Accepted by topic author Gab008

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)

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
Message 7 of 7
(8,911 Views)