class-design

.NET ORMs, immutable value objects, structs, default constructors, and readonly properties

末鹿安然 提交于 2020-01-12 18:47:13
问题 I am just getting started with .NET ORMs, to the point where I haven't even decided between Entity Framework and NHibernate. But in both cases, I'm running into a problem in that they seem to want me to compromise the integrity of my domain model in various ways, especially on finer points of C# object design. This is one of several questions on the subject. I am very used to enforcing immutability on appropriate properties with a pattern that looks like this: public class Foo { private

how to create an interface around classes that already exist but cannot be modified in java

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 15:51:22
问题 Suppose I already have 2 classes in my code: class SomeOrder { String getOrderId() { return orderId; } } class AnotherOrder { String getOrderId() { return orderId; } } How to create an interface around both these classes which is: interface Order { String getOrderId(); } Ideally, I would modify the code so that SomOrder implements Order and AnotherOrder implements Order but the catch here is that they belong in a package that I cannot control or edit (i.e. they come from an external jar). My

UML class diagram: is this how to write abstract method and property?

為{幸葍}努か 提交于 2020-01-03 07:30:13
问题 When I was creating the first time an uml class diagram for a small C# project I had some trouble with the properties. At the end I just added the properties as a variable with <<property>> at the start. Now Im wondering how do I solve this with an abstract method? Should I just add <<abstract>> to the method an fine? Im doing something like this: ----------------------------------- | <<abstract>> | | MyClass | ----------------------------------- |<<property>> + a : int | |<<property>> + b :

Copying Methods from Member

一世执手 提交于 2020-01-01 11:05:10
问题 I have a simple, low-level container class that is used by a more high-level file class. Basically, the file class uses the container to store modifications locally before saving a final version to an actual file. Some of the methods, therefore, carry directly over from the container class to the file class. (For example, Resize() .) I've just been defining the methods in the file class to call their container class variants. For example: void FileClass::Foo() { ContainerMember.Foo(); } This

How to design a class with “annotated” fields?

孤街浪徒 提交于 2019-12-31 14:35:38
问题 Imagine we have some sort of protocol with hundreds of message types, each of which we want to model by a C++ class. Since each class should be able to process each field automatically, a natural solution is to just have an std::tuple with all the required types: std::tuple<int, double, char> message; print(message); // the usual variadic magic This is all fine and well. However, now I want to give each field a name, and I want to be able to use the name when referring to the field in my code

How many constructors should a class have?

喜夏-厌秋 提交于 2019-12-31 13:33:09
问题 I'm currently modifying a class that has 9 different constructors. Now overall I believe this class is very poorly designed... so I'm wondering if it is poor design for a class to have so many constructors. A problem has arisen because I recently added two constructors to this class in an attempt to refactor and redesign a class (SomeManager in the code below) so that it is unit testable and doesn't rely on every one of its methods being static. However, because the other constructors were

How many constructors should a class have?

…衆ロ難τιáo~ 提交于 2019-12-31 13:33:07
问题 I'm currently modifying a class that has 9 different constructors. Now overall I believe this class is very poorly designed... so I'm wondering if it is poor design for a class to have so many constructors. A problem has arisen because I recently added two constructors to this class in an attempt to refactor and redesign a class (SomeManager in the code below) so that it is unit testable and doesn't rely on every one of its methods being static. However, because the other constructors were

C++ circular reference problem

纵饮孤独 提交于 2019-12-31 06:53:21
问题 I have 2 classes: DataObject and DataElement . DataObject holds pointers to (only) DataElement s, and a DataElement contains pointers to several types, among which a DataObject . This used to be no problem, since I only use pointers to DataObject s in DataElement , so a forward declaration of DataObject in the header of DataElement is enough. Now, however, I try to add a destructor to DataElement , in which I need a delete on a DataObject . On this the compiler says: dataelement/destructor.cc

UML Class Relationships

巧了我就是萌 提交于 2019-12-30 10:26:51
问题 I would like to confirm whether I am on the right track when identifying common UML class relationships. For example, is the relationship between: 1 a stackoverflow member and his/her stackoverflow user account categorized as a composition relationship or an aggregation relationship? At first I thought it was an association because this member "has a" account. However on second thought, I am thinking its composition because each "part" (user account) belongs to only one whole (user) at a time

what is the differences between class and dataType

做~自己de王妃 提交于 2019-12-30 08:14:51
问题 As i read through UML specification that: class has a set of attributes/operations and data type has a set of attributes/operations 1)with regards to attributes/operations of data type what this means? because i don't know how such a data type has attributes and operations? 2)What’s the main difference between a class and a datatype? 回答1: according to UML 2.4.1 specification A data type is a special kind of classifier, similar to a class. It differs from a class in that instances of a data