This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help with design of stock class when the stock's web data is part of a group.

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy All,

I am trying to write software that is maintainable, and I have a design question.

I have a base class, AbstractStock that contains the stock name, a filed for List<StockPrice> where StockPrice contains a date and a closing price.
I have a YahooStock class that is derived from AbstractStock and adds the ability to download the historic stock data. No problem with this class, works fine.
I have another class, TSPStock, that is also derived from AbstractStock, and implements price download from tsp website. This class is giving me trouble because the web page presents the prices for all the funds (10) in one table, that is changed by end date. So, I am processing all the tsp funds when the first fund is created.
There is a container class, portfollio, that holds a list of AbstractStock objects, or TSPStocks and YahooStocks.

OK, I have this all working, and here's my question.

Keep in mind that the goal is to write code that is maintainable, since I will have to work on this in the future as the web interface changes or add new funds are added or other goals come up. And I'm getting a little older now so I'm able to forget more sooner lately.

The usage of these class is something like



In the TSPStock constructor, it makes sens to call an update function that stores the historic data locally by follow these steps
1) gets the last date from historic data file, or a date before TSP existed if the historic data doesn't exist.
2) gets a list of end dates from the tsp web site
3) compares the list of end dates with the file last date to generate a list of requried end date
4) loops overs the required end dates and adds the new web data to the file data
5) writes out the file data

So, here's my design question. Should I use an auxalliary class for processing the collection of TSPStock download / file storage? If I use a single class for TSPStock, then I need a field that is a Vector<TSPStock>, and this field is processed and written to the file. However, it may be cleaner to use two classes, TSPStock and TSPDataObject where TSPDataObject holds the Vector<TSPStock> field. I've already finished the one class solution, but as I was trying to clean up the code organzation, I was thinking that it would be better to have a separate class the holds the Vector<TSPStock> and processes the download / file processing. Now, I've got the 2nd class almost done, and I'm wondering what if someone tried to make an object of the TSPDataObject class. Practically, constructing objects of TSPDataObject could be used to create/request TSPStock object. But, I'd like to prevent construction of TSPDataObjects, and only allow access through the TSPStock constructor. Can the constructor be made private somehow?

One more thing. The program will generate a large number of portfolios, with a range of stocks in them. And I plan to have multiple threads doing the processing, so the read/write/update of the historic data has to allow synchronized threads. Any suggestions on that?

John
 
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since noone answered yet, a few questions, where I'm not sure if I understood you correctly:

John Vorwald wrote:
I have another class, TSPStock, that is also derived from AbstractStock, and implements price download from tsp website. This class is giving me trouble because the web page presents the prices for all the funds (10) in one table, that is changed by end date. So, I am processing all the tsp funds when the first fund is created.


What is TSP? Or are you referring to the Telecomunicacoes de Sao Paulo S.A. company?
Are you parsing a website and try to extract the stock-prices? If yes, are you doing the same thing with your YahooStock class? Represents the YahooStock class only the Yahoo-stock? If so, do you want to create for every stock another concrete class? That's how I understand it at the moment. And no, this is NOT a good idea. Neither creating concrete classes for every possible stock nor parsing websites for information like stock quotes (for that you could use an API like Yahoos Finance API (http://developer.yahoo.com/finance/) or the one from Google (http://code.google.com/intl/de-DE/apis/finance/))
 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TSP is thrift savings plan, which is the retirement plan for federal employees, and it has 10 fund options for putting you savings in.

The TSPStock class can hold any of the tsp funds, while the YahooStock class can hold any of the stocks/commodities/etc available on yahoo financial site. Both classes are derived from an AbstractStock class. In addition to the name, number of share, exchange, last trade, the stock objects also hold the price history for analysis. There is a class called Portfollio that holds a collection of AbstractStocks. So, I can have several stocks from Yahoo and a few stocks from TSP (since there are only 10). For now, I've decided to go with the data access object approach, so there is a TSPDAO and a YahooDAO. The constructor for the DAO takes a Portfolio, and sorts out which stock it needs to download data for, and checks for local data and if needed goes and gets the historic data for the list of stocks in the portfolio. There is a single function called update which return the Portfollio with the stocks modified to contain the historic data. DAO keeps a copy of the historic data local to minimize downloading.

Regarding using parser xyz, I'd rather write my own parsers instead of using someone elses, since the web interface is subject to random changes. I have even written my own html/xml parser, but for now I've relaxed my standards and am currently interfacing with javax.swing.text.html and extending HTMLEditorKit.ParserCallback class. It's actually rather simple to write a parser since all you have to do is search for start and end tags, and possibly some parameter tags, and maybe some relaxing logic for when the start/end tag doesn't have a partner. That html/xml tag data structure of information can be readily stored in either a tree format, or a linked list. There's a lot of web pages that don't meet standards, and tend to need special care/treatment, so I think it's useful to have your own parser that you thoughly understand. Right now, my parser only about 45 lines or so, and half of those are for member overloads that are for tags I'm not using, so it keeps the logic nice and tight and clean. I've looked at other parser that have more than 45 classes, and I'm not sure what they are trying to do. Previously, I implement the full w3 standard, and I think that was only about 200 lines. Also, my software logs into various private web sites, and I prefer to use my own code for doing secure login, ssl transfers, encrypted data storage, etc.

Thank you for your comments and suggestions. Keep up the good work!
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic