|
No way am I reading through that code.
Natepizzle wrote: a static class for the portfolio ... a static class called netConnection
I recommend against that; those are not good candidates for static classes in my opinion.
|
|
|
|
|
I thought a static class would be the right choice as I have only 1 portfolio and 1 connection, therefore, not needing to create multiple instances of those classes. Do you have anything further to add to support your argument?
|
|
|
|
|
Natepizzle wrote: not needing to create multiple instances
You don't know what the future holds, don't limit flexibility.
There is also the argument that if the class holds state (as yours do) it should not be static.
Static is better suited to library routines.
|
|
|
|
|
Use static for things that are inherently unique, not for things that are currently unique.
|
|
|
|
|
First, it seems what you are modeling here now ... the "molecular object" ... is a single, static, instance of a "portfolio." And, the "atomic" elements of the portfolio are stocks/options owned now.
Certain attributes of those stocks/options are fixed (name, expiration date, purchase price); others need to be continually re-calculated based on changing current market prices (you don't state at what interval your application needs to poll the data source, the website, to refresh the calculated attributes).
At a higher level of abstraction: you are also updating the net worth of the portfolio at a current point in time, and, considering that options expire, I think you need to think about how you notify/present/warn the user of the application that an option is about to expire, or, when an option has expired, you remove it from the collection. Similarly, when you sell a stock: do the proceeds then feed back into some running total of net gain, or net loss, so that the portfolio reflects an entire "history" ?
It would seem "natural to me" that you would model a collection of portfolios, and the portfolio elements could be restricted in some ways to contain only bonds, or only puts, or calls, or whatever. Or, whatever: mix 'em all up: you're the artist here
This scenario suggests to me that your "macro object" that you model here is a container comprising a collection of Portfolio objects. The idea that there may be "types" of Portfolio objects, all of which share common functionality, suggests to me a class Portfolio (abstract ? virtual ?), with common fields, Properties, methods, etc., and, then, various Portofolio-Type classes/objects that inherit from the class Portfolio. Or "enforcing commonality" via use of Interfaces ?
If you choose to "mix 'em up:" what do you think about considering that what you are modeling ... at the atomic level ... is not a stock, bond, or option, but an "investment asset:" with one attribute of that investment asset being (fleshed-out as an Enum ?) its type: stock, bond, option-call, option-put, sell-short ?
The one "conspicuous" absence in your current design goal, to my eyes, is the lack of specification of the polling method to update current prices/values, and how it is controlled, or configured, by the end-user, or application. In the real world, the time-limited nature of options (puts, calls), the "tick" of each time-interval that moves you closer to expiration date may have a big influence on how frequently you monitor any given individual option.
There's also the possibility of having sell-at-price, and stop-loss sell-by, orders in place.
However, these are all just general ideas in reaction to the idea of modeling a portfolio, and I'm not saying there's anything wrong with your goals as stated here.
In terms of use of "static" classes: I certainly agree with Luc's very wise comment re: "inherently unique," and suggest you think of a static class as a place which is a repository of utility methods, in this scenario.
There are a lot resources here on CP related to web-scraping, and I'd definitely recommend you do a search for them, and take a look at your elaborate use of RegEx's to see if you could simplify that. RegEx's, however, can be compiled.
I'd also look around for a web service that may return stock/option information in a simpler format (JSON ? rather than XML ? or ?) that would be easier to parse ... assuming hsx.com is not just a name you created, a "placeholder" for accessing said information. Demand for stock/option information is so great, there are bound to be lots of ways to get that information on the web.
Assuming the user will want to create, use, change, their portfolio, and assuming your application does not run continuously: what about the issues of saving "state" when you close the application. Are you going to serialize, send a bunch of whatever off into a "Cloud:" and, if the application is closed, and then re-opened: should it automatically refresh ... warn the the user it is not currently refreshed ... or should the user, through the UI, control when refersh occurs.
My personal vote is for some dramatic visual indicator on the main UI when the current prices are not currently refreshed, or cannot be accessed to be refreshed.
If you do get involved in saving and restoring "state," do see Mehdi Gholam's remarkable work on a super-duper JSON writer/reader here on CP:[^].
Do you wish the user to be able to save "snapshots" of the Portfolio, or to introduce a "history mechanism" into the Portfolio: in which the Portfolio itself contains the entire data for each refresh that has occurred ?
Specific comments on the code:
1. in a static class ... or in a dynamic class ... there's absolutely no need to use private "backing field" variables as well as a public Property: ... unless you are using a very old version of .NET: just use the short-form like: "public static double CurrentPrice { get; set; }" : the private "backing field" will be created for you automatically.
2. by using slightly different casing in variable names in your parameter lists, you can eliminate a lot of the the use of syntax like: "this.optionType = optionType;" typical practice would be to name the variable, or Property, "OptionType," and the parameter name "optionType."
I think imagining what kind of UI a user would want to use your classes/objects is a good exercise ... even if, in this case, you don't choose to implement one ...
good luck, best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
modified 26-Dec-11 6:55am.
|
|
|
|
|
Thank you for the advice and the detail in your reply. Honestly, I haven't been able to plan out where I want this application to go but with your reply I will look into the things you talked about that I haven't ran into yet. Thank you.
|
|
|
|
|
This post is somewhat inspired by Blubbo's recent post, here, on creating a set of methods with similar signatures and return values.
I think I can describe what I want to ask more clearly in the context of some "real code:"
Assume you have a WinForm with three NumericUpDown controls, and one ComboBox presenting a list of three choices: "Multiply, Divide, Power:"
private Func<decimal, decimal, decimal> PE;
private decimal x, y;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
x = numericUpDown1.Value;
y = numericUpDown2.Value;
switch (comboBox1.SelectedIndex)
{
case 0:
PE = (d1, d2) => d1*d2;
break;
case 1:
PE = (d1, d2) => d1/ d2;
break;
case 2:
PE = (d1, d2) => (decimal) Math.Pow((double) d1, (double) d2);
break;
default:
break;
}
try { numericUpDown3.Value = PE(x, y); }
catch (DivideByZeroException dZero) { }
catch (OverflowException oFlow) {}
} What I would appreciate your opinions on are:
1. is there any real performance value inherent in making use of Func and lambdas here ... assuming we "scale" this simple example up to include a very large number of "case" conditions in the "switch" block ?
2. for those of you with understanding of what happens in IL "under the hood:" does anything about assigning those lambdas to the Func "PE" in the "case" statements make the "switch" statement any more complex, or less performant ... once again assuming this example is really scaled up ?
3. since 'throw' is a valid command for exiting a case statement in a switch block, would you ever throw an error in a case statement when possible ?
4. what's your opinion on using something like this compared with the use of Interfaces, as suggested in responses to Blubbo's question ?
thanks ! ... and Merry Xmas ... Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
1. I don't know, but I would prefer to eliminate the switch somehow
2. Ditto
3. I would never throw simply to exit a control structure (I don't even like break and continue)
4. Interface
What comes to mind (in my usual over-engineered way) is a class that holds a delegate to some method. You populate your ComboBox with them, the ToString is used as the text. When selected, you execute the method.
|
|
|
|
|
- The readability, and hence, maintenance would suffer. Lambda's and delegate's are fast.
- It's an extra assignment. Assignments don't take much time though.
- We don't use exceptions to influence the flow of the program. Ever.
- Your switch reminds me of the
Strategy pattern.
BillWoodruff wrote: thanks ! ... and Merry Xmas ... Bill
Enjoy your holidays
Bastard Programmer from Hell
|
|
|
|
|
1. I don't know, I have to do some benchmarks to find out myself.
2. It normally should not make the switch statement less performant, but again, it depends.
3. It's a very bad programming practise to control flow using exceptions.
4. A better solution would be to use Strategy pattern, it would make the code more readable and easy to follow by all programmers, not just the .NET ones.
|
|
|
|
|
I Using C# and DirectX.Capture I Can capture Webcame, but I can't figure out how to mix it with rotating text, should I create a filter?
|
|
|
|
|
Hello,
I am not sure if this is allowed or not – if this post is against any Rules i apologize in advance and this post can be removed.
I am in the process of creating a open-source project to track the Psychological Mood of a person, this application will be used by people visiting psychologists.
Target Audience
People that are currently in therapy or want to keep track of mood changes. The program is based on CBT.
Aims
To provide to the end-user the tools for him to be able to monitor his mood.
To provide to the therapist additional information for the client through the automatic generation of graphs.
To reduce the international suicide rate.
To make this application available for everyone to use.
We are looking for some volunteers to help with Coding of the Project.
The Project has been seperated into three parts for easier management.
The Desktop Application is coded in VB.NET and using an ORM called nHibernate.
Project URL: http://moodtracker.codeplex.com
The Web-Based Application will be coded in C# and use MSSQL as the Database.
Project URL: http://webmoodtracker.codeplex.com/
The iPhone Application.
Project URL: http://iphonemoodtracker.codeplex.com/
We're aiming to develop a feature-rich Psychological Mood Tracker to help the end-users as much as we can.
If anyone is interested please feel to apply to the CodePlex Project Page.
Thank you in advance.
Constantinos
|
|
|
|
|
I don't believe this belongs here. You could post the Jobs board.
No comment
|
|
|
|
|
hello guys... If this is not the right forum, plz guide me to the right one. I have successfully made my first crystal report with VS 2010. But I want to add page header and design my column IDs little bit. I did so (at design time in Crystal Report using 'Format Object') and ran the project. But it does not show the page header at all and does not show the formatted column id. whats wrong? thnx
|
|
|
|
|
We don't seem to have a forum for Crystal Reports but a lot of CR questions get posted in the Quick Answers[^] section, so it may be worth trying there.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Why don't you use Microsoft ReportViewer? It's much better and easy for generating reports.
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hi,
This is my first post and i am quite new to c# but am really enjoying the learning process, i have been looking at the many examples on the code project site for a few weeks now and have not found anything that i think covers what i want to do.
I want to read in an hours worth of audio in a wav file and check that there is audio in it. the audio is recorded from a radio receiver into the computer and stored in hour chunks.
i just need to be sure it is storing audio (radio program) not static noise (lower level) or very low level (wrong audio source etc.)
Any input or advice on how to achieve this would be greatly appreciated
thanks
Simon
|
|
|
|
|
The simple approach is to define a threshold between useful audio and silence. Discard audio segments that fall below this threshold.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
This probably should be in the C# forum, since the question really goes down into what is silence in audio data and what type of audio encoding is within the WAV file. What it comes down to is you're going to have to interpret the PCM data in the WAV file.
|
|
|
|
|
|
|
How to add the video String(OSD), I use DirectX.Capture Class Library?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Capture capture = null;
private Filters filters = new Filters();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
capture = new Capture(filters.VideoInputDevices[0], filters.AudioInputDevices[2]);
try
{
if (capture.PreviewWindow == null)
{
capture.PreviewWindow = panelVideo;
}
else
{
capture.PreviewWindow = null;
}
}
catch (Exception ex)
{
MessageBox.Show("Unable to enable/disable preview. Please submit a bug report.\n\n" + ex.Message + "\n\n" + ex.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
capture.FrameEvent2 += new Capture.HeFrame(CaptureDone);
capture.GrapImg();
}
private void CaptureDone(System.Drawing.Bitmap e)
{
this.pictureBox.Image = e;
capture.FrameEvent2 -= new Capture.HeFrame(CaptureDone);
}
private void button3_Click(object sender, EventArgs e)
{
if (!capture.Cued)
capture.Filename = @"F:\demo.wmv";
capture.RecFileMode = DirectX.Capture.Capture.RecFileModeType.Wmv;
capture.Cue();
capture.Start();
}
private void button4_Click(object sender, EventArgs e)
{
capture.Stop();
}
}
}
modified 22-Dec-11 5:44am.
|
|
|
|
|
Hi All,
I have a website (web application) publish to an IIS server and it is work fine, but the problem is if i open or request the site from the internet more than 10 times the site go down and dosen't work from the internet or from the local network, its work just from the IIS (go to the IIS and Browse the site from it).
And i restart the IIS but this step doesn't solve the problem. The only thing that solve it is to restart the whole Machine (Computer Server).
please help me if you know any solution.
Best Regards.
Zeyad Abed Aljalil
Senior Developer
Isra' Software & Computer Co.
|
|
|
|
|
You already posted this on Quick Que/Ans.
Continue on that and, stick on one. don't spam the board with reposts.
check my comment on Quick Que/Ans Post.
IIS Web Site Problems[^]
Rajesh B --> A Simple Programmer <--
modified 22-Dec-11 5:00am.
|
|
|
|
|
Include the link(of the question) in your message.
|
|
|
|
|