LabVIEW Development Best Practices Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

OOP Class Design Question

I am looking for some help wrapping my head around the class design.

 

I am working on a Class Hierarchy to handle our data transfer communication within our company and am not sure how to configure the classes.

 

The basic design is this:

 

Transport Method - Parent Class

DirectSQL, HTTP, Local - Child Classes

RequestSN, Save Data - Methods

 

Now, within the Child Class and method, the data format has the option of being XML, JSON, SQL or TEXT.

 

For example, I could use the Save Data method under HTTP, and the Save Data could then be implemented using XML, JSON, etc data formats.

 

I am struggling with where to put the Data Format class.   Do I need to implement Save Data - XML, Save Data - SQL, Save Data JSON, etc for each method, which essentially does away with the data format class (in my opinion)?

 

Do I add the DataFormat class as private data of the Transport Method class, and then access the data member in each of the methods?

 

 

Kenny

0 Kudos
Message 1 of 3
(206 Views)

Hi Kenny,

 

I would have a separate formatter class heirarchy with an abstract parent and specific children for each of them.

 

Then you can store a copy in the transport class that the child classes can use to perform the formatting.

 

At some point, you would have to decide the right formatter and set it in the transport class, normally wherever you create this.

 

This keeps it inline with the SOLID principles as well, if your not familiar with them it is worth reading around online - there is lots of material on them.

 

Cheers,

James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 2 of 3
(192 Views)
Highlighted

I recommend something along the lines of the bridge pattern from the GOF.

 

https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_3?ie...

 

https://en.wikipedia.org/wiki/Bridge_pattern

 

You can implement it exactly as James mentions.

Sam Taggart
CLA, CPI, LabVIEW Champion
DQMH Trusted Advisor
automatedenver.com
0 Kudos
Message 3 of 3
(183 Views)