Best practice/pattern for flag values
I'm writing a class that has several public static final int fields that can be combined bitwise. I'm debating whether to number all the default values zero, have zero represent the defaults but NOT have public fields numbered zero, or number every field with a power of two.
I've thought of the following pros and cons:
The advantages of the first pattern include allowing the defaults to be set explicitly in user code, making the coder's intent apparent. The disadvantages include it being an error to test flags against the default (zero) values, and that error not being apparent to the user.
The advantages of the second pattern include there being no default values to erroneously test against. Disadvantages include the inability to set defaults explicitly.
The advantages of the thid pattern include being able to test against defaults and set defaults explicitly. Disadvantages include the possibility of erroneously setting two mutually exclusive flags.
I'm leaning toward the third pattern, because I can make it my own problem to test for mutually exclusive flags. Is there anything else I haven't considered?
Edited by: kjkrum on Oct 2, 2010 9:50 AM
kjkrum wrote:
I'm writing a class that has several public static final int fields that can be combined bitwise.Perfect, do it.
public class Person {
// female is 0, male is 1
public static final int FLAG_GENDER = 1;
public static final int FLAG_EMPLOYEE = 2;
public static final int FLAG_CLIENT = 4;
protected int flags = 0;
public String getGender() {
return (isFlag(FLAG_GENDER) ? "male" : "female");
public boolean isEmployee() {
return isFlag(FLAG_EMPLOYEE);
public boolean isClient() {
return isFlag(FLAG_CLIENT);
public void setGender(String gender) {
setFlag(FLAG_GENDER, (gender == "male"));
public void setEmployee(boolean value) {
setFlag(FLAG_EMPLOYEE, value);
public void setClient(boolean value)
setFlag(FLAG_CLIENT, value);
protected boolean isFlag(int flag) {
return ((flags & flag) == flag);
protected void setFlag(int flag, boolean value) {
if(value) {
flags |= flag;
else {
flags &= ~flag;
}Done, that took me a whole 10 minutes with rewrites.
I'm debating whether to number all the default values zero, have zero represent the defaults but NOT have public fields numbered zero, or number every field with a power of two.
I've thought of the following pros and cons:
The advantages of the first pattern include allowing the defaults to be set explicitly in user code, making the coder's intent apparent. The disadvantages include it being an error to test flags against the default (zero) values, and that error not being apparent to the user.
The advantages of the second pattern include there being no default values to erroneously test against. Disadvantages include the inability to set defaults explicitly.
The advantages of the thid pattern include being able to test against defaults and set defaults explicitly. Disadvantages include the possibility of erroneously setting two mutually exclusive flags.
I'm leaning toward the third pattern, because I can make it my own problem to test for mutually exclusive flags. Is there anything else I haven't considered?
Edited by: kjkrum on Oct 2, 2010 9:50 AMWhat's more important... you sitting here trying to make a philisophical decision, or getting the class definition written?
Edited by: pierrot_2 on Oct 3, 2010 3:28 PM
Similar Messages
-
What is the best design pattern for this problem?
No code to go with the question. I am trying to settle on the best design pattern for the problem before I code. I want to use an Object Oriented approach.
I have included a basic UML diagram of what I was thinking so far.
Stated simply, I have three devices; Module, Wired Modem, and Wireless Modem.
In the Device Under Test parent class, I have put the attributes that are variable from device to device, but common to all of them.
In the child classes, I have put the attributes that are not variable to each copy of that device. The attributes are common across device types. I was planning to use controls in the class definition that have the data set to a default value, since it doesn't change for each serial number of that device. For example, a Module will always have a Device Type ID of 1. These values are used to query the database.
An example query would be [DHR].[GetDeviceActiveVersions] '39288', 1, '4/26/2012 12:18:52 PM'
The '1' is the device type ID, the 39288 is the serial number, and the return would be "A000" or "S002", for example.
So, I would be pulling the Serial Number and Device Type ID from the Device Under Test parent and child, and passing them to the Database using a SQL string stored in the control of the Active Versions child class of Database.
The overall idea is that the same data is used to send multiple queries to the database and receiving back various data that I then evaluate for pass of fail, and for date order.
What I can't settle on is the approach. Should it be a Strategy pattern, A Chain of Command pattern, a Decorator pattern or something else.
Ideas?elrathia wrote:
Hi Ben,
I haven't much idea of how override works and when you would use it and why. I'm the newest of the new here.
Good. At least you will not be smaking with a OPPer dOOPer hammer if I make some gramatical mistake.
You may want to look at this thread in the BreakPoint where i trie to help Cory get a handle on Dynamic Dispatching with an example of two classes that inherit from a common parent and invoke Over-ride VIs to do the same thing but with wildly varying results.
The example uses a Class of "Numeric" and a sibling class "Text" and the both implement an Add method.
It is dirt simple and Cory did a decent job of explaining it.
It just be the motivation you are looking for.
have fun!
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Best practice guide for Batch Load utility in Oracle UCM.
Hi,
Is there any best practice guide for Oracle UCM Batch Loader utility.
We are looking for information regarding batch size in terms of number and size of contents. Also is there any loading time standards considering the contents are uploaded in filesystem where filestore provider is configured?
Thanks,
KrishnenduHi ,
There are no specific set of steps / practices for batch loading contents to ucm . It would be very much dependent on how many contents does the user have to load to UCM and how well the server is configured in terms of performance .
You can get more details from the following documentation link : http://docs.oracle.com/cd/E21043_01/doc.1111/e10792/c02_settings009.htm
Thanks,
Srinath -
I canu00B4t get best practices documentation for COPA
Hello all:
Can anybody send me the best practices documentation for CO-PA (B86: CO-PA Baseline)? because I can´t get from this link
http://help.sap.com/bp_biv133/index.htm
You can send to these e-mail
[email protected]
[email protected]
Thanks a lot in advanced.hi Victor,
sorry, material distribution via email isn't allowed here. not sure why you cannot download, here i can right click that link and 'save as target'.
for pdf try following
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/fb07ab90-0201-0010-c489-d527d39cc0c6
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ff61152b-0301-0010-849f-839fec3771f3
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1910ab90-0201-0010-eea3-c4ac84080806
hope this helps. -
Best Practice paper for Security
Does anyone have or know of a Best Practice Paper for Security?
Thanks,
Melissahttp://www.petefinnigan.com is another excellent security resource-- he has a couple of different checklists.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Where does one find the Oracle Best Practice/recommendations for how to DR
What is the Oracle Best Practice for install/deployment and configuration of ODI 11g for Disaster Recovery?
We have a project that is using Oracle ODI 11g (11.1.1.5).
We have configured all the other Oracle FMW components as per the Oracle DR EDG guides. Basically using the Host ip name/aliasing concept to ‘trick’ the secondary site into thinking
it is primary and continue working with minimal (or no) manual reconfiguration. But will this work for ODI? The FMW DR guide has sections for SOA, WebCenter and IdM, but nothing for ODI.
Since ODI stores so much configuration information in the Master Repository..when this DB gets ‘data guarded’ to the secondary site and promoted to Primary…ODI will still think it is at the ‘other’ site. Will this break the actual agents running the scenarios?
Where does one find the Oracle Best Practice/recommendations for how to DR ODI properly?
We are looking for a solution that will allow a graceful switchover/failover with minimal manual re-configuration.user8804554 wrote:
Hi all,
I m currently testing external components with Windows Server and I want to test Oracle 11g R2.
The only resource I have is this website and the only binaries seem to be for Linux OS.You have one other HUGE resource that, while it won't answer your current question, you'd better start getting familiar with if you are going to use Oracle. That is the complete and official documentation, found at tahiti.oracle.com
>
Does anybody know how I can upgrade my Oracle 11.1.0.7 version to the R2 release?
Thanks,
Bertrand -
Best Practice guide for purchasing - payment card processing
Hello All,
\Is there any Best Practice guide for Payments by credit card/ Payment card Processing.
The biz process is:
The purchasing department users purchase goods/services using their corporate credit cards. They obtain a credit card voucher/receipt for the purchase made. The credit card co. turns in the credit card statements/files once in a month the Accounts Payable matches the receipts with the statements/files & makes the payments.
Will reward points.
Thanks & Regards,
ArpitaHi Arpita,
You might want to check this link
http://web.mit.edu/sapr3/docs/webdocs/purchpay/ppCC.html
http://www.bitpipe.com/tlist/Payment-Processing.html
http://whitepapers.sapinsideronline.com/view.cfm?session=&white_paper=4
Thanks,
Jenny
award points if helpful -
SAP Best Practice Guide for QM data pull to BI
Hello Gurus,
I am looking for SAP Best Practice Guide for Quality Mangament data modelling required for BI. That will solve my problem, to go through all the documentation before concluding to finalize the SAP Delivered Business Content objects.
Need your input.
Thanks,
Lasya.Need your inputs experts.
Thanks,
Lasya. -
Hi Team,
Could you please send if you have any Best Practice document for configuring Service Parameters on CUCM 9.1.1. That would really help.
Thanks,
GuruHi
There's no 'best practice' as such, but there are a few that I think should be default:
Enabling CDR, On-Hook Pickup, CFwdAll Override... but really the settings are specific to the requirements of the deployment.
Aaron -
Is there any Best Practice Document for OEDQ development?Please share.
Is there any Best Practice Document for OEDQ development?Please share.
Hello, Please check the below projects, you would get better idea on the best practices like Naming Standards, which processors to use, how to bundle the jobs, external tasks etc.,
edq-cds-data-quality-health-check-9.0.4.(645).dxi
edq-cds-initialize-reference-data-9.0.4.(645).dxi
Regards,
Bala Govi -
Best practice document for ACE30
Can someone point me to a best practice document for the ACE30. I am specifically looking at best practices as they relate to resouce allocation, logging, FT, and snmp. I am migrating from CSM so the VIP/Server configuration is basically set. I am looking for areas that pertain to the ACE as a whole.
Thank youGood afternoon,
I'm afraid there isn't a best practices document as such, however, I would suggest you to have a look at the ACE section in doc-wiki (http://docwiki.cisco.com/wiki/Cisco_Application_Control_Engine_%28ACE%29_Troubleshooting_Guide).
This document can give you some useful insights on different topics, including (but not limited to) resource allocation.
I hope this helps
Daniel -
Best practice document for SRM
Hi all
Is there a best practice document for SRM setup and Qucksizing tool for SRM-MDM
thanksHello,
SRM related best practice building block is S60 - Self-Service Procurement (Procure 2 Pay)
Please find the link:
http://help.sap.com/bp_bblibrary/600/html/S60_EN_DE.htm
Hope this will be useful.
Thanks
Ashutosh -
Best Practice Analyzer for Exchange 2013
Greetings,
I have upgraded the messaging infrastructure from Exchange 2007 to Exchange 2013.
I want to test the Health of the system through ExBPA for Exchange 2013.
But i don't find any setup for Exchange 2013 like it was in 2010.
I went through an article by Office365 community, according to which for In-premises Exchange also we need to have office 365 account (can use trial account also) to get the downloader file for ExBPA 2013.
http://community.office365.com/en-us/w/deploy/office-365-best-practices-analyzer-for-exchange-server-2013.aspx
But to run the setup the servers needs to be connected to internet.
And, i don't want to expose my environment to internet in any condition.
Somebody, please suggest me if there is any setup available so that i can install directly without exposing to internet.
Thanks in advance.
Best Regards,
K2Welcome to Exchange 2013.
Exchange Server 2013 doesn't come with ExBPA for health check. This might help
http://exchangeserverpro.com/powershell-script-health-check-report-exchange-2010/
Apart from that you can run these commands too
Get-ServerHealth -Identity Exchange2013ServerName
Test-ServiceHealth
Cheers,
Gulab Prasad
Technology Consultant
Blog:
http://www.exchangeranger.com Twitter:
LinkedIn:
Check out CodeTwo’s tools for Exchange admins
Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. -
Best Practice tips for publishing Captivate 8 project?
Does anyone have any Best Practice Tips for publishing Captivate 8 projects? Is HTML5/Flash the most universal?
We will begin testing/training before our LMS is functional.
We have no shared network capability or SharePoint type platform. Project is too large for e-mail even when zipped.
I am thinking that we will have to use thumb drive/CD along those lines.Hi There ,
Please refer to the below links :-
Adobe Captivate Help | Preview and publish Responsive projects
Adobe Captivate Help | Publish projects as HTML5 files
Adobe Captivate * Publishing Projects
Regards ,
Ajit -
Any best practice recommendations for controlling access to dashboards?
Everyone,
I understand that an Xcelsius dashboard compiled into a .swf file contains no means for providing access control to limit who can or how many times they can run the dashboard. Basically, if they have a copy of the .swf they can use it as much as they'd like. To protect access to sensitive data I'd like to be able to control who can access the dashboard and how many times or how long they can access it for.
From what I've read it seems the simplest way to do this is to embed the swf file into a web portal that requires a user to authenticate before accessing the file. I suppose I can then handle how long they can access it from the back end.
If I do this, is there anyway a user can do something like <right click - save as> on the flash file to save it on their local machine? Is there a best practice means for properly protecting the dashboard?
Any advice would be appreciated,
Jerry WinnerEveryone,
I understand that an Xcelsius dashboard compiled into a .swf file contains no means for providing access control to limit who can or how many times they can run the dashboard. Basically, if they have a copy of the .swf they can use it as much as they'd like. To protect access to sensitive data I'd like to be able to control who can access the dashboard and how many times or how long they can access it for.
From what I've read it seems the simplest way to do this is to embed the swf file into a web portal that requires a user to authenticate before accessing the file. I suppose I can then handle how long they can access it from the back end.
If I do this, is there anyway a user can do something like <right click - save as> on the flash file to save it on their local machine? Is there a best practice means for properly protecting the dashboard?
Any advice would be appreciated,
Jerry Winner
Maybe you are looking for
-
I have a instrumental ringtone in itunes how do i transfer it to my iphone so i can have it as a ringtone?
-
Calling Function Module in Update Task
Hello Experts, Can anyone let me know about Calling Function Module in Update Task. Why do we use this " In Update Task " ?? How do we Use ?? What is the Use... ?? Kindly let me know.... Thanks and Regards Pramod
-
Compressing Data Passed Through WebService
Hi there... Before I start explaining the problem, I am not an expert in webservices and weblogic. 1- I am having a webservice that accepts lots of textual information and responds with lots of textual information as well. Is there an option in weblo
-
Run or display the output in Oracle developer form runtime web
Hi guys, I have installed oracle forms10g in windows 7. im using firefox v.2. when i run the form, the Oracle developer form runtime web is not opening. the output is display in the mozilla firefox itself. but how to run or display the output in Orac
-
Need help with serious problem
Hi. I thought this was a simple problem, but it turned out to be more complicated than I thought. I have been experimenting with JFrames and found a problem when trying to disable the maximise button of a JFrame. The program starts up maximising the