Object-Oriented philosophy problem

  • Thread starter Thread starter Sojourner01
  • Start date Start date
  • Tags Tags
    Philosophy
AI Thread Summary
The discussion revolves around the challenges of constructing a Monte Carlo simulation tool using object-oriented techniques in Visual C#. The user describes their current object hierarchy, which includes a Lattice class containing a 3D array of Site objects, a Site class with boolean properties for validity and occupancy, and a Polymer class with Monomer objects that reference Site locations. The user expresses frustration with the structure, feeling it complicates the implementation of Monte Carlo transformation methods. They specifically seek guidance on how to effectively set the neighbours array of each Monomer to point to the corresponding Site objects in the Lattice. Suggestions include having the Site class reference the parent Lattice for neighbor retrieval or using a Factory model for Site instantiation. The user realizes their misunderstanding of object references versus value assignment, acknowledging that their programming approach needs refinement. They anticipate needing further assistance as they work to improve their code structure.
Sojourner01
Messages
371
Reaction score
0
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.
 
Technology news on Phys.org
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.
 
Apologies for my blind ignorance; I've realized 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top