Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Object-Oriented philosophy problem

  1. Jan 29, 2008 #1
    I have a problem in constructing a program. The principle is a monte carlo simulation tool using object-oriented (or, strictly I suppose, object-based) techniques written in Visual C#.

    So far my object hierarchy is constructed as follows:

    A Lattice class, which contains:
    A 3-dimensional array of Site objects

    A Site class, instances of which have:
    two booleans to define whether they're i) valid in an FCC lattice ii) occupied by anything
    A 3-dimensional array of other Site objects defining its neighbours

    A Polymer class, which contains:
    An array of Monomer objects

    A Monomer class, instances of which have:
    A Site object defining where they are

    I have come to the conclusion that this system is a mess and doesn't define things in a way that can be acted on by Monte Carlo transformation methods I plan to implement. I've walled myself in here, and it's going to take a considerable amount of work to restructure this program to get it to work.

    At the very least, I want to get the 'neighbours' array of each monomer to point to Site objects in the Lattice's array of sites. I'm not sure how to do this. I don't want to use lookup tables, since they're arbitrary and not very portable.

    I appreciate that this topic is a bit of a mouthful, so please do inquire if - which will almost certainly be the case - my explanation is unclear or lacking.
     
  2. jcsd
  3. Jan 30, 2008 #2

    -Job-

    User Avatar
    Science Advisor

    Can you explain a little bit better why you're having difficulties with setting the neighbours array to point to the neighbour sites on the Lattice? You can either have the Site class keep a reference to the parent Lattice, in which case it can use something likemyLattice.GetSite(mySite.X+1, mySite.Y+1, mySite.Z+1) to get neighbors, or you can have the Site constructor take in the array of neighbours as a parameter - and use a Factory model to instantiate Sites - the Lattice class would have a method GetSite(x, y, z) which instantiates a Site instance, populates the neighbours array and returns it.
     
  4. Jan 31, 2008 #3
    Apologies for my blind ignorance; I've realised in the last 24 hours how staggeringly simple my error was. There isn't a problem with saying array2[n] = array1[not necessarily n], when they're both arrays of references to the same object type. For some reason I conceptualise the = operator as assignment by value when it's really stating a link between reference and object.

    My programming still a maze, s i may have to check back here for some more pearls of wisdom in tidying it up.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?