wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes The concept of properties of an Object at a particular time in Java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The concept of properties of an Object at a particular time in Java ?" Watch "The concept of properties of an Object at a particular time in Java ?" New topic
Author

The concept of properties of an Object at a particular time in Java ?

David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
I was curious to know if there is a concept of TimeProperties in Java for any Class. Something that could store the properties of an Object of that Class at an instant of time. The properties can change with time.
Thats why I felt the need for such a class.

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8244
    
  23

David S Hansen wrote:I was curious to know if there is a concept of TimeProperties in Java for any Class. Something that could store the properties of an Object of that Class at an instant of time. The properties can change with time.

The basic answer to your question (as with most things in Java) is: Yes.

But I think we need a few examples of what some of these "properties" would be before we can say categorically.

And if your question is "can I write this generically for ANY object" the answer, again, may well be 'yes'; but we'd need an awful lot more information about precisely what you want to do.

TellTheDetails (←click).

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Winston Gutkowski wrote:
David S Hansen wrote:I was curious to know if there is a concept of TimeProperties in Java for any Class. Something that could store the properties of an Object of that Class at an instant of time. The properties can change with time.

The basic answer to your question (as with most things in Java) is: Yes.

But I think we need a few examples of what some of these "properties" would be before we can say categorically.

And if your question is "can I write this generically for ANY object" the answer, again, may well be 'yes'; but we'd need an awful lot more information about precisely what you want to do.

TellTheDetails (←click).

Winston


For example consider a stock (from the stockmarket). A stock can have several parameters that change with time. Some parameters change quickly while some change after a long time.
I want to keep a track of properties that change quickly over an hour or so. That is why I want a class for this purpose.


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

David S Hansen wrote:
For example consider a stock (from the stockmarket). A stock can have several parameters that change with time. Some parameters change quickly while some change after a long time.
I want to keep a track of properties that change quickly over an hour or so. That is why I want a class for this purpose.


There is no built-in language or API feature that lets you track an arbitrary object's state changes over time. For specific classes that you define, though, and even for other arbitrary classes up to some point, it shouldn't be hard to do, depending on your specific requirements. A simple brute force approach that would work with objects that are deeply copyable and that follow JavaBeans conventions would be to simply make copies at each change, or at specific intervals in time, and wrap those copies in your own class that includes a timestamp.

Of course, that could get expensive in terms of memory and CPU cycles, so you may have to be more sophisticated in what you copy. But since you didn't provide specific requirements, it's impossible to provide more specific suggestions.

Two other tools that could prove useful are Annotations and Aspect-Oriented Programming. I don't know a lot about either one, and again, know nothing of your actual requirements, but since these features deal with "out-of-band" or "meta" information, they seem like candidates worth investigating.
Jinu Vijay
Greenhorn

Joined: Sep 19, 2011
Posts: 20

Just reading through your requirement, I'm guessing you are probably looking for a Observer design pattern. This allows for watching for a change of state/property (for e.g. of the stock) and perform some activity based on it.

I could find this link useful to explain further (along with a working sample)

http://javarevisited.blogspot.in/2011/12/observer-design-pattern-java-example.html


Java too does provide this pattern via classes -- Observer and Observable. Another good link, along with sample, is available here:

http://www.java-samples.com/showtutorial.php?tutorialid=381
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Jinu Vijay wrote:Just reading through your requirement, I'm guessing you are probably looking for a Observer design pattern. This allows for watching for a change of state/property (for e.g. of the stock) and perform some activity based on it.

I could find this link useful to explain further (along with a working sample)

http://javarevisited.blogspot.in/2011/12/observer-design-pattern-java-example.html


Java too does provide this pattern via classes -- Observer and Observable. Another good link, along with sample, is available here:

http://www.java-samples.com/showtutorial.php?tutorialid=381


Yes, that sounds useful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The concept of properties of an Object at a particular time in Java ?