class-design

Class usage in Python

I write a lot of scripts in Python to analyze and plot experimental data as well as write simple simulations to test how theories fit the data. The scripts tend to be very procedural; calculate some property, calculate some other property, plot properties, analyze plot... Rather than just writing a procedure, would there be an benefits...

I'm creating a Polygon class in Objective-C, should centroid calculation be a function or a method?

I'm doing this to learn about class creation and to test geometry routines. As I build the class I will add other polygon-related functionality like getting the bounding box, determining convexity, turning the poly into triangles and the like. Is it best to put that kind of code in functions or in methods of the class? ...

Override member data in subclass, use in superclass implementation?

In Java, is it possible to override member data in a subclass and have that overridden version be the data used in a super class's implementation? In other words, here's what I am trying to get to happen, and it's not happening: abstract public class BasicStuff { protected String[] stuff = { "Pizza", "Shoes" }; public ...

Constructive criticism on this class

Hi, I've just reviewed some code that looked like this before public class ProductChecker { // some std stuff public ProductChecker(int AccountNumber) { var account = new AccountPersonalDetails(AccountNumber); //Get some info from account and populate class fields } public bool ProductACriteri...

C# - Any standard way to divide a class into regions?

I was wondering if there is some standard way to divide a class into regions. almost every project is using a different "region approach" (even classes within the same project). We pay so much attention to naming conventions and so little to the class's structure. I think that introducing some standard will make it much easier on us to ...

How to read data for nested classes?

Hi all, I'm sorry if my question isn't clear. I have a class contain some properties and one of them is "Parent" which the same type of this class. when i read data from Database i set the suitable value for each property. But how could i put the "Parent" property when i read it from database as "ParentID". If it's not clear I'll put...

How to make a singleton class threadsafe?

I am implementing a singleton class in Java to make sure no more than one instance of the class is created. ...

How can a singleton class use an interface?

I read at many places that singletons can use interfaces. Some how I am unable to comprehend this. ...

How can I reuse an instance of a webservice?

I am running a service A which has a class X. I am going to deploy another service B on same machine which is using this class X. How can I make sure that the same instance of service A is reused instead of another. PS:Service written in JAVA. Adding: Both these services are Axis2 services. Service B is hot-deployed. Service B used cla...

Implementing IEquatable<T> where T is an interface.

I have a domain model that is trivially represented by the following. IMyInterface ClassA : IMyInterface ClassB : IMyInterface What I want is to implement IEquatable in such a way that I can write code something like. if(dynamicallyCreatedInstanceOfClassA == dynamicallyCreatedinstanceOfClassB) { // Do something relevant } My fi...

Class with just Shared functions - Why is it bad?

Hi, I have a class called MembershipHelper, which I am using in my ASP.NET project. It looks like this: Public Class MembershipHelper Public Shared Function IsMultiStoreUser() As Boolean return Roles.IsUserInRole(....) End Function Public Shared Function IsAdmin() As Boolean return Roles.IsUserInRole(....) ...

What relevant differences are there between anonymous and predefined classes in Java?

I have a large tree-like data structure of objects which behave mostly identical but differ in one or two methods that calculate some keys used to navigate through the structure. The divergent behaviour depends on where the objects are in the structure. I was starting out with an abstract base class and have several subclasses that impl...

Field level attribute vs Property level attribute

Hello, This is something I find rather curious, that a lot of third party libraries such as FileHelpers and Command Line Parser are designed to work at field level rather than property level. Is there a particular reason why so many have chosen to target their tools at public fields rather than properties? My personal feeling is that p...

C++ DAL Design - Include Foreign Key Table as Composite Object

Hi, I recently posted this C++ DAL question about how best to design a 'loadCar' method in a C++ DLL, with the consensus being that 'bool DAL::loadCar(int id, Car&) {}' would be the best signature to use. Now, it so happens that in a lot of our use cases the client code will often want to retrieve the car's manufacturer with the car ob...

Temporary Storing data entered in steps in class in asp.net

how can i store different data enetered using multiple steps? Its 4-5 step procedure, user can go through each step & at the final submission i want to store it in database. I want to create class to store this data & store the data in object of that class & use it from session. I just want to know what type should i use to store multipl...

prevent height sizing at design time

I'm working on a custom user control. How can I prevent the HEIGHT ONLY of the control from being modified during the design-time interface. ...

C++ reference to a shared_ptr vs reference

All, I recently posted this question on DAL design. From that it would seem that passing a reference to an object into a function, with the function then populating that object, would be a good interface for a C++ Data Access Layer, e.g. bool DAL::loadCar(int id, Car& car) {} I'm now wondering if using a reference to a boost::shar...

How to design my class

I have a class, which returns three properties. First property is dependent on some parameter, second one is dependent on the first property and third one is dependend on the second property. What is the best way, to implement this type of class, is there a appropriate design pattern for this one? Below I pasted two versions of my code...

C# Class function members declaration & implementation

Is there a concept in C# of class definition and implementation similar to what you find in C++? I prefer to keep my class definitions simple by removing most, if no every, implementations details (it depends on several factors as you may know, but generally I move towards leaving most member implementation details outside the class def...

Designing a class with **Exceptions**

When I design a class I often have trouble deciding if I should throw an exception or have 2 func with the 2nd returning an err value. In the case of 2 functions how should I name the exception and non exception method? For example if I wrote a class that decompresses a stream and the stream had errors or incomplete I would throw an exc...