class-design

Class Design Question

Let's say I want to make a HumanBody class. And I want to store the length of each limb. HumanBody.LeftArmLength = 14; HumanBody.RightArmLength = 14.1; HumanBody.LeftLegLength = 32; HumanBody.RightLegLength = 31.9; That's all well and good, but it seems like it would be better to do something like: HumanBody.Arm.Left.Length = 14; Hu...

Custom Sorting in .NET

I have designed a Class for Parent Child relationship class Category { public string CatName; public string CatId; public IList<Category> childCategory = new List<Category>(); public void addChildCat(Category childCat) { this.childCategory.Add(childCat); } public Category SortedCategory(Category ...

Find info about class in java, software design?

I have a bunch of classes extending an abstract Base class. Each subclass takes an array as in the constructor, (different length depending on class). These classes could be written by other people. What is the best way to figure out the length of the array the class needs? I could: (A) Require that each derived class have a static meth...

Class design 'dilemma'

I never did proper class design, so bear with me. Let's say we have a Project class. Then let's say we have a ProjectGroup class that has the same members as the Project class, plus a list of Projects. Should ProjectGroup be the superclass of Project or is ProjectGroup a specialization of Project and the former should be a subclass of ...

C++ Class design - easily init / build objects

Using C++ I built a Class that has many setter functions, as well as various functions that may be called in a row during runtime. So I end up with code that looks like: A* a = new A(); a->setA(); a->setB(); a->setC(); ... a->doA(); a->doB(); Not, that this is bad, but I don't like typing "a->" over and over again. So I rewrote my ...

Performance of Singleton Class Instance Method vs. Static Class Method in PHP?

Hi all, I'm interested in objective analysis of which is more performant; calling instance methods of a singleton class or methods of a static class. I've already seen this so I'm not looking for a discussion about the difference between the two or a discussion of which is "better." I'm only interested in relative performance between t...

Create custom exception or use built-in exceptions?

Currently I'm in the process of writing a client class that utilizes DNS, Sockets, and SSL among other classes that love to throw exceptions. Other people will be implementing this class, so I was wondering what the best practice is for throwing exceptions. Should I create my own custom exception so they know that it is my class throwi...

Where do class convert methods go

Many of my classes end up needing convert functions. DataRow -> Object converters ViewModel <-> Model Converters My question is where should the functions live? Option 1: Inside the source class public class Employee { public EmployeeViewModel ToViewModel() {} } var vm = myEmployee.ToViewModel() Option 2: Inside the destinatio...

UML mapping with c#

There are two classes Person and Employee when it mapped to c# code public class Person { private string Name; } public class Employee : Person { private string Department; public string GetName() { return "Person Name"; } } My question is where can i write the getters and setters for this private attr...

AS3 OOP visualization logic - linking filters and data source

I'm trying to visualize the results of a quiz in ActionScript 3.0. What I would like some input on is how to best link the "filters" (top right corner in attached image) to the data source in a flexible OOP way. The result array now contains both number of correct answers and meta data about the person taking the quiz. The meta data cou...

What do you use to document the detailed plan for your classes?

I'm wondering what work-flow and or tools people use to document the details of classes they plan to create. Specifically, where and how do you manage the nitty gritty details. For big picture stuff I make use of class diagrams. Specifically I use the class diagram tool built into Visual Studio. I also end up creating a lot of Visio diag...

Is it ok to hide a static method?

I have an abstract Catalog class as follows. It has a static method OpenCatalog() which is used to return a specific concrete catalog based on the type of location provided. Once it has determined the type of catalog it then calls a specific OpenCatalog() method of the correct concrete catalog type. For example I may have an implementati...

Best practice concerning private arraylist and other such constructions

Hello all, I have the following class which I'm fighting over how to implement. The question is whether or not it makes sense to have a private collection item, in this case an arraylist, a a member. I am well aware it is considered best practice to have getters and setters for any class members, but in this case having a getter and set...

benefit of properties in business objects ?

In my projects I am using 4 layers (userinterface, custom types, business logic and data access layer). I heared a lot about benefits of properties but in practicle I just used business objects for transfering data between layers and not getting any benefit of properties. I read that business rules, validations and checks can be implem...

How a class that wraps and provides access to a single file should be designed?

MyClass is all about providing access to a single file. It must CheckHeader(), ReadSomeData(), UpdateHeader(WithInfo), etc. But since the file that this class represents is very complex, it requires special design considerations. That file contains a potentially huge folder-like tree structure with various node types and is block/c...

Creating read-only versions of classes in a complex object structure

In my current project I need to be able to have both editable and read-only versions of classes. So that when the classes are displayed in a List or PropertGrid the user is not able to edit objects they should not be allowed to. To do this I'm following the design pattern shown in the diagram below. I start with a read-only interface (I...

What special considerations should I make when creating an object model that will be consumed by a desktop application and web site?

I'm writing a tool in C#.Net that will be used to generate Catalogs of content which users can browse. Initially I am creating a WinForms based interface, but in the future I'd like to be able to create a web based interface as well. So I've been careful to generalize the interface to a Catalog so that it does not depend on a specific UI...

How to dependency inject a class / type?

I'm struggling with a design problem and I don't want my code to become a mess because of a bad solution. Rather than give a poor analogy I'll just explain my exact case. I'm trying to write a clone of Wii Play Tanks, and I'm having trouble designing the Tank classes. Tank itself is the only such class, it uses dependency injection for ...

Which language can change class member dynamically in run time?

I know in Ruby can add and modify method of class dynamically in run time. what about other language? what is C# ,can in this language modify or add some method and ... in run time and dynamically? ...

PriorityQueue of Objects from an Inner Class - Can't find constructor

Hi all, I need a priority queue of objects but I keep getting this error: symbol: constructor PriorityQueue(anonymous java.util.Comparator<map.Node>>) location: class java.util.PriorityQueue<map.Node> PriorityQueue<Node> pq = new PriorityQueue<Node>(new Comparator<Node>() Here an excerpt from my code: public class map { static ...