Which Design Pattern?
Hi all,
First of all, im pretty new to design patterns so apologies for any errors. I am creating a program that maintains a large index of string values (maybe a vector or hash table) but for the sake of performance, i would like more than one instance of the application to run at once, so that they can each add to the index.
As i said, i am new to patterns, but this seems like an ideal scenario for the Singleton. Would i be right in this assumption and could you give me any advice or example code as to how i might implement it?
Thanks very much
Wraith
georgemc wrote:
Imagist wrote:
final public class Singleton
private Singleton() { }
final private static class SingletonHolder
final private static Singleton instance = new Singleton();
final private static Singleton getInstance()
return SingletonHolder.instance;
}This is the paradigmatic way to implement a singleton in Java these days. There are other ways more commonly used, but this has the advantage of allowing lazy loading AND thread safety without incurring the performance penalty of synchronization.
Edited by: Imagist on Nov 19, 2008 9:53 AM
public class Singleton
private Singleton() { }
final public static Singleton instance = new Singleton();
}Oh look. Lazy loading, thread safety and simplicity, all in one lump. Why did you bother making the class final, anyway? The singleton pattern as prescribed by the GoF book explicitly talks about inheritanceAs far as I can tell, that's not lazy-loading. If you call Singleton.someStaticMethod(), the classloader will initialize the instance variable, causing the constructor to call. Admittedly, that doesn't happen often. I haven't looked at Bloch's book in a while, but if I remember correctly this is the method he recommended.
I made the class final because that allows more optimizations to occur at compile time. The JIT compiler usually figures stuff like that out, but in some older versions of Java it might not happen until it has been running for a while. I use older versions of Java often, so that's a good habit to be in (and it doesn't hurt anything).
Similar Messages
-
Which Design Pattern and how to design using OOP this scenario
I am having trouble designing a module, can anybody help me?
Because it will be hard to maintain this kind of module, I also think that this can test my skill of design pattern usage.
Requirement
This is basically an agricultural project (web application). I need to design a module where some calculation takes place.
There are different crops involved like maize, tomato, okra etc. Each of these crops has different traits.
Each trait has a measurement scale which lies in integer like 200-1000. Now let's say I have planted the crop and done measurement noted down the traits. Now I want to do some sort of measurement. Some measurements are simple and some are complex.
Example
Lets take an example of crop maize. I have recorded observations for 15 traits. (We'll use trait1-trait15 as examples, the actual name can be like plt_ht, yld, etc.)
I recorded 5 observations for each trait:
trait1 trait2 trait3 trait5 trait6..... trait15
01,02,03,04 01,02,03,04 01,02,03,04
User logs into system and selects his crops and enters data for these observations. I have to calculate either average or sum of the data entered for each trait.
Complexity / centre of the problem
So far it's simple but complexity comes when I have some different formulas for some of the traits.
Example: trait YLD has a formula based on which I have to calculate its value, which may also depend on some other traits. Each different crop can have different traits.
All this I am able to do - whenever user selects crop I will check for those specific traits and do calculations (if it's not a special trait then I either average or sum it, based on db entry), but there is a lot of hard coding.
I would like to have suggestions on a better way of handling this.
My code needs to handle both simple and complex calculations.
Simple calculations are easy, I have take average of value entered for trait.
The problem comes when I have to do complex calculations, since each crop have different traits with their own formulas, so to calculate I have to check for crop and then for complex trait. So I have to hardcode the trait name of complex traits.
Can any tell me how I can design this using Java oops [?!?] so that I can make it generic?
I have about 10 different crops. Some calculations are specific to crops, so there will be lot of code like the if below:
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("MZ") && traitName.equalsIgnoreCase("Shelling")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPoint, dataTraits, traitValues,dataPvalues, dataPoint, type);
avg=avg*dataPoint;
traitAvg=getMaizeYeild(traitName, traitAvg, population, avg, hybrid, area);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YLDGM")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPoint, dataTraits, traitValues,dataPvalues, dataPoint, type);
//avg=avg*dataPoint;
Object[] dataValues=getOKRAYield(traitName, traitAvg, population, avg, dividend,hasZeroValue,hybrid,repl);
traitAvg = (HashMap<String, Float>) dataValues[0];
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("HP") && traitName.equalsIgnoreCase("w1-w10")) {
avg=HybridTestDataUtility.calculateAvg(traitName, dataPts, dataTraits, traitValues,dataPvalues, dataPoint, type);
avg=avg*dataPoint;
Object[] dataValues=getHotPepperYield(traitName, traitAvg, population, avg,dividend,hasZeroValue,hybrid,repl);
traitAvg = (HashMap<String, Float>) dataValues[0];
hasZeroValue = (HashMap<String, ArrayList<String>>) dataValues[1];
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("TLSSG_70")) {
traitAvg=calculateTLCV(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues,50);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("TLSSG_100")) {
traitAvg=calculateTLCV(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues,50);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("YVMV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("TO") && traitName.equalsIgnoreCase("ELCV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_60")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_90")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg,dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("YVMV_120")) {
traitAvg=tomatoYVMVCalculation(traitName, traitAvg, dataPoint, dataTraits, hybrid, repl, traitValues, dataPvalues);
} else if(cropId.equalsIgnoreCase("OK") && traitName.equalsIgnoreCase("ELCV_60")) {Can anybody think of a way to make a generic approach to this?There are crops and each crop have traits , traits are actually a mesuremet
scale to decide growth of a seed of a particular crop.
This module is to for planters to observe growth of seeds sowed of certain
crops and take down n no of observation for each trait and upload in csv format.Once they enter
data i have to either avg out the values or sum the values or sometimes
there are more complex function that i have to apply it may differe for each
trait .This is the whole module about.Just to give an idea about how they
will enter data
Hyubrid(seed) trait1 trait2 trait3 trait5 trait6..... trait15
Hybrid1 01 02 03 04 01
HYbrid2 04 06 08 04 01
HYbrid2 04 06 08 04 01
HYbrid2 04 06 08 04 01
HYbrid2 04 06 08 04 01
Once they enter data in this format i have to give result something like
this.
Here avg colum does not necessaryly mean avg it can be sum or any formula
based resutl.Hybrid is the seed for which they record the observation.
I have shown avg column only for two tratis it is actually for all the
traits.
Hyubrid(seed) trait1 Avg trait2 avg trait3 trait5 trait6..... trait15
Hybrid1 01 01 02 04 03 04 01
HYbrid2 04 04 06 10 08 04 01
HYbrid2 04 04 06 12 08 04 01
HYbrid2 04 04 06 14 08 04 01
HYbrid2 04 04 06 12 08 04 01
Hope this clarifies atleat a but
The data are not correctly indented but there is no way i can format it. -
Regarding which design pattern to use for this scenario???
hi guys
I am working on a J2EE application where I need to do translations for 3 different scenarios. It is basically a conversion from service order objects to invoices.
First from a service order object to an invoice.
Second a conversion from a transaction table.
Third a conversion from a remote system.
Finally the product is an invoice..
What design pattern can i use ....is strategy pattern a good idea??
Thanks
JHi,
I think your problem is in result state. You can you sequencial block but for approve or reject you need to set target for each result state. Here I am providing a link. I think you will get your solution here please go through it.
http://help.sap.com/saphelp_nw2004s/helpdata/en/44/429bbd709914bce10000000a155369/frameset.htm
if you have any query please let me know.
Thanks
Chandan -
Design patterns in portlet development
Hello,
I am a student at the Technical University in Munich, Germany and I am working on a university project on design patterns for portlets.
The focus of my work is researching the best practices when developing a web portlet, especially which design patterns are the most suitable for portlets development.
For example, the MVC pattern is one of the most popular design patterns for portlets.
I am writing to you to ask which design patterns are used in the development of your portlets from the SAP Enterprise Portal.
- What design patterns do you use for your portlets?
- Do you use MVC among others?
- Do you have your own design patterns?
- Do you use any templates or guidelines for portlet development that involve design patterns?
I am looking forward to your answer. Any answer would help with the research, as experts interviews are part of my work in the project.
I appreciate any references you consider to be related to my search.
Thank you,
Julia Alexandrescu
Department of Informatics
Technical University Munich
Email: [email protected]Hi raaj,
I have a query related to this.
I am a beginner to portlets.
Say I have an existing struts application.What all do i need to modify or add to make a .portlet file out of it so as to make it deployable in Weblogic 8.1 SP3?
Is adding a portlet.xml enough?
if yes, what would the portlet.xml look like?
Do i need to add a separate class as well?
I couldnt get any sufficient answers from other forums.
Can you please help?
Thanks & Regards,
Nishant -
Hi all,
Which design patterns could be applied in coding EJB? I don't know if my question is clear enough, but what I really want to know is which design patterns I could use with EJB and how could I use them this way? (Some example situation)
Regards,
Filipe Fedaltoi think it depends of what u intend to do..
e.g. i think (maybe i'm wrong, any relevant replies are welcome!) that u could use a stateless session bean to implement some facade, delegating entities creation to some non-bean classes? or why not a stateful session bean to implement a factory (when entities creation depend on client preferences)? -
How to avoid multiple if else using design patterns.
Hi,
Which design patterns is used to avoid lot of if else in our code . Say for example if the user press 1 the out put should be one, if he press 2 it should be two like this upto 10. So we need to include lot of if-else part. How to avoid the multiple if else using design patter for this scenario. I can't find the solution for this problem can you guys help me?.I'm too lazy to read a whole text book, but the first google link provides a code sample which made me laugh.
http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html
double getSpeed() {
switch (_type) {
case EUROPEAN:
return getBaseSpeed();
case AFRICAN:
return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts;
case NORWEGIAN_BLUE:
return (_isNailed) ? 0 : getBaseSpeed(_voltage);
throw new RuntimeException ("Should be unreachable");
}My implementation of The Bridge Over The Parrot Shop
package forums;
import java.util.Random;
abstract class Bird {
private static final Random random = new Random();
abstract double getAirSpeed();
public double getBaseSpeed() {
return randomDouble(18.96);
protected static double randomDouble(double max) {
return random.nextDouble() * max;
protected static int randomInt(int max) {
return random.nextInt(max);
class EuropeanSwallow extends Bird {
double getAirSpeed() {
return getBaseSpeed();
class AfricanSwallow extends Bird {
private int _numberOfCoconuts;
public AfricanSwallow() {
this(randomInt(4));
public AfricanSwallow(int numberOfCoconuts) {
_numberOfCoconuts = numberOfCoconuts;
double getAirSpeed() {
return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts;
public double getLoadFactor() {
return randomDouble(3.12);
class NorwegianBlue extends Bird {
private boolean _isNailed;
private double _voltage;
public NorwegianBlue() {
this(randomInt(10)<2, randomDouble(12.0));
public NorwegianBlue(boolean isNailed, double voltage) {
_isNailed = isNailed;
_voltage = voltage;
double getAirSpeed() {
return _isNailed ? 0 : getBaseSpeed(_voltage);
double getBaseSpeed(double voltage) {
return getBaseSpeed() * (1+(voltage/Math.PI));
public class AirSpeedTest
public static void main(String[] args)
System.out.println("EUROPEAN: "+new EuropeanSwallow().getAirSpeed());
System.out.println("AFRICAN: "+new AfricanSwallow().getAirSpeed());
System.out.println("NORWEGIAN_BLUE: "+new NorwegianBlue().getAirSpeed());
}... and the requisite background for the uninitiated [NORWEGIAN_BLUE|http://www.youtube.com/watch?v=4vuW6tQ0218] and [EUROPEAN v AFRICAN|http://www.youtube.com/watch?v=4b4bGAoVR7g].
You have to know these things when you're a King you know.
Cheers. Keith. -
hi all,
I am preparing for the CLD. I would like to know which design pattern is suitable for sprinkler controller?
My opinion state machine pattern not suitable.Use rain selector and low water pressure as inputs to the timer state, along with the timing information of course. Then timing stops when the specified time has occurred, or one of the other inputs is outside the designated range. The next state may be different for each of those conditions. This is the power of the state machine architecture, that it can respond to inputs differently based on the current state.
Lynn -
Design Pattern for Discussion Forum
Hi all,
We have to develop a application similar to our discussion forum. Which Design Pattern is more useful? Can u discuss the archietecture? We use J2EE except EJB.
Thanks,
MuraliWe expect people to at least make an attempt at the question and present a few ideas particularly college assignments / home-work questions. We dont expect everybody/thing to correct, you will receive little criticism for being wrong, if you show a willingness to put in some effort. You will be criticised for and likely receive no help if you simple expect members to do your work.
Some patterns to be think about.
The achitectural pattern of this forum is thin client, 3-tier, presentation, functionality and storage.
Consider the following patterns.
- Model View Controller
- Facade and/or Proxy
- Command
- Composite
- Memento -
Design pattern for several conditions
Hi;
I would like to implement an search algorithm which use many conditions (search criteria).
For Example
Begin :
If criteria A && B are OK => if criteria C is OK => etc...
Else criteria D && F are OK => if criteria C is OK => etc...
Else etc...
which design pattern or another design correspond to my requirement ?
Regards;You are missing the point somewhere. Object-oriented design patterns are tools used to design object-oriented applications. There is a certain limit to size that is associated with warranted usage.
In other words, the issue of your post is a trivial element of conditional processing. There is no such design pattern to apply to such a thing because that is not what design patterns are used for.
Aside, some forum "genius" is going to post some application of a design pattern to this issue and then call me crazy. Looking forward to it :o)
Your question would be better suited if it asked for what type of conditional processing algorithm might work well. In Java there are a few to work with. If statement, do while statement , while statement, case, etc. -
Design pattern for swind application development
Hello all,
I am trying to develop a new swings application with the centralized database connectivity for the data transaction .Any one please tell me which design pattern is mostly suitable for the GUI application development using swings .
Thanks in advance
sowjanyaPu - this is your decision.
In order to know which design patterns are suitable for you, you should know what the design pattern do.
So I suggest to read about design patterns:
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
Note also that ther exists a framework called Spring.
Greetings
Thorsten -
SERVICE LOCATOR ?? Is it really an interesting Design pattern??
Hi everybody,
i've a problem with the J2EE Design Pattern "Services locator" (it's a singleton).
It is said that by making use of a Service Locator we can :
- hide to the client the complexities of initial context creation, EJB home object lookup,and EJB objectre-creation.
- multiple clients can reuse the Service Locator object to reduce code complexity, provide a single point of control, and improve performance by providing a caching facility.
But i would like to understand at which side should that service locator object reside??!!??
If it is at server side then the clients need well an initial context in order to make a lookup on that object.
Conclusion :
the service locator doesn't hide the complexities of initial context!!
Furthermore the client has to perform a look-up on that service locator object!! The only advantage left is caching facility.
If it is at client side, each client needs his own services locator object
Conclusion :
multiple client don't reuse the same service locator. What's the advantage to be a singleton ???
There is certainly something that i don't understand so help me please!! Thanks.Hi Yves,
But i would like to understand at which side should
that service locator object reside??!!??
If it is at client side, each client needs his own
services locator object
Conclusion :
multiple client don't reuse the same service locator.
What's the advantage to be a singleton ???The service locator resides on the client side and is implemented as
a singleton. Since it is possible that there could be multiple
class loaders/JVMs on the client side, and therefore, multiple
instances of the "singleton" service locator. This is typical
in a distributed environment (e.g. servlets/JSPs in a web-tier
cluster using service locator). Thus service locator is not
a truly "distributed singleton" object. But, the empahsis
is to design the service locator such that it does not hold
any state that needs to be replicated across multiple
instances across different JVMs as mentioned. Thus, there
is no need for multiple clients to use the "same" service locator,
but still the benefits of implementing this pattern is realized.
By making it a singleton, and keeping it from holding state
that needs to be replicated, we realize the benefits of this pattern.
You may also want to visit the J2EE Pattern interest list
and see these relevant discussions :
Topic: Service Locator and passivation
http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=1026
Topic: Caching EJBHome interfaces
http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=9226
Topic: Using Service Locator for Data Source caching
http://archives.java.sun.com/cgi-bin/wa?A1=ind0106&L=j2eepatterns-interest#31
hope this helps,
thanks,
-deepak -
Does any body have any design patterns of JSF Web Application Developping?
Can any one answer me some questions?
#1.I am an amatuar of people who develop Web Application.For some reason,We choose the JSF to develop our item.through some introduction,I know the UI component of JSF is resided in Server side,is it right?but I am a little confused that:if there are many users who are exploring our jsf website.(to simplify my question,image I had just one web page and just one button)How many UI components(buttons) will be there?How it(they?) works?
#2.Does any body have the success experience (for example design pattern)to develop web applications?if We just concern about the Add,Delete,Modify,Query operations of some data.
I just do my job according to my feeling.
I will give every page a pagebean(backing bean),and I am not sure how to combine the business data with the pagebean.some one suggested that I should use delegate pattern to separate my business log and page logic.But I am still confused by following things:
#2.1 does JSF have the same ability to help us construct the model dialog just like swing to
help us control the operation flow?
#2.2 If there is not,Does the following way work?I put every tabledata's property as corresponed component.if user choosed the row in the table,My Listener will syncronize the row data to the components.But
#2.2.1 if JSF has the components according to the web users' number,how can My Listener tell which component should be update?Should I maintain the map?
#2.2.2 If the problem I imaged above is false,Does any body can tell me how to custom the ListDataModel,so I can use it like Swing?because now I can just use some view data to insert into ListDataModel,but after some selection operation,my business object must be find according to the selected data,it is not an interesting job!
I am waiting for your advice!Ok I'll try to explain Step by step please correct me if I make any mistake because I have not played much with shared variables.
To create a shared variable to an RT target go to the target if tou have already otherwise add an RT target by right clicking the Project>>Add targets and Devices
Then in the target Right clikc and select the variable as shown below.
Then once the Shared variable settings window opens Enter a variable name and then Select the type "Network Published"
In the right side you can select the data type for the shared variable and even you can choose your custome controls.
After selecting the data type go for the Network and select buffering if required else leave it if you are planning to use the variable just for display purpose.
Then you can enable the RT FIFO if required (Not able to explain how it works and why it is used).
Then after completing the Shared variable setup you can access the variable in the VI in both the Host and the RT.
You can bind the variable to a control so that if any data from the RT is coming you can read the data from that control.
Once you have placed your shared variable in the BD you can change the access typr to read or write depending on your need.
This might not explain the complete shared variable concept but I believe that this would defenelty give you a kick off to start using the shared variable. Please correct or add more comments if anybody know better.
Good luck.
The best solution is the one you find it by yourself -
Design patterns for updating a fact table
I have a fact table and about 10 dimensions.
One of these dimensions can be missing values, so the fact table row will link to an UNKNOWN value.
When the correct value is finally entered in the dimension table i want to update any associated fact rows.
Whats the most efficient way of doing this?I know i have to use a lookup transformation ;-)
I wouldnt be at teh stage of even having a fact table if i didnt know that! I was looking for a design pattern, not the name of a shape!
The solution i went with was to take a hard line on any rows with unknown values. If when importing the data there are unknown values for two of the most important dimensions, those rows are not inserted into the fact table, but instead pushed to an ErrorLog
table.
Users run a report that shows what this table contains and if they really want those rows, they insert the correct dimension values and rerun the import, which will only import any rows not already in the fact table.
This way:
1. all sorting & filtering issues are resolved as there will be no unknown rows for the most important dimensions used in sorting and filtering.
2. we can quickly see any rows with unknown values and figure out whats wrong. its always missing reference data that the client didnt think to give us. a quick insert of the dimension data and import and the rows get imported.
thanks for the replies. -
Design Patterns/Best Practices etc...
fellow WLI gurus,
I am looking for design patterns/best practices especially in EAI / WLI.
Books ? Links ?
With patterns/best practices I mean f.i.
* When to use asynchronous/synchronous application view calls
* where to do validation (if your connecting 2 EIS, both EIS, only in WLI,
* what if an EIS is unavailable? How to handle this in your workflow?
* performance issues
Anyone want to share his/her thoughts on this ?
KrisHi.
I recently bought WROX Press book Professional J2EE EAI, which discusses Enterprise
Integration. Maybe not on a Design Pattern-level (if there is one), but it gave
me a good overview and helped me make some desig decisions. I´m not sure if its
technical enough for those used to such decisions, but it proved useful to me.
http://www.wrox.com/ACON11.asp?WROXEMPTOKEN=87620ZUwNF3Eaw3YLdhXRpuVzK&ISBN=186100544X
HTH
Oskar
-
Producer/Consumer Design Pattern with Classes
I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port. I thought this would be a good time to start using Classes. I created a GPIB class which contains member data of: Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do. I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware. This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture.
However, in other applications (without classes) I typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction. My queue data is a cluster of an "action" enum and a variant to pass data. Is it OK to use this pattern with classes? I created a vi and it works fine and attached is a png (of 1 case) of it.
Are there any problems doing it this way?
JasonJTerosky wrote:
I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port. I thought this would be a good time to start using Classes. I created a GPIB class which contains member data of: Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do. I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware. This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture.
However, in other applications (without classes) I typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction. My queue data is a cluster of an "action" enum and a variant to pass data. Is it OK to use this pattern with classes? I created a vi and it works fine and attached is a png (of 1 case) of it.
Are there any problems doing it this way?
Including the error cluster as part of the private data is something I have never seen done and ... well I'll have to think about that one.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction
Maybe you are looking for
-
Lost pictures and documents in restore process
pavilion g7 can this data be recovered by another restore or some other method?
-
How to convert ABAP Reports in other languages during runtime.
Hi Gurus, In SAP during Log-in, I select "EN" sa my language. Is there a way where in I will log-in using English language but upon generating abap report, the result is in Chinese characters? Thanks in advance.
-
Object level authorizations for deffirent user restrictions
Hi i have 1 object, this object have only 3 values? i need authorizations for this object at report level? rsa1- i keep authorization relevant? rsecadmin i can include this object , here i need give from value and to value? i have 3 values only? supp
-
Clicking noise when playing rented movie on apple tv
I am having trouble with my apple tv making a clicking noise when playing a rented movie from the iTunes store. Any suggestions?
-
Is it possible to remove the Virtualbox icon from the Dock while it's running? Thanks for the help.