Questions tagged [class-design]

Refers to structural definition of class unit in object-oriented languages.

1125 questions
0
votes
4 answers

IList Collection Class accessing database

I have a database with Users. Users have Items. These Items can change actively. How do you access the items in a collection type format? For the user, I fill all the user properties at the time of instantiation. If I load the user's items at the…
Mike
  • 3
  • 3
0
votes
1 answer

Declaration of function to generate vector of class with a vector of another class

I have 2 classes: class Item; class Component; And I have a function to generate a vector of Items from a vector of Components static vector generateItemsFromComponents( vector components ) { vector vi; // ... …
user3235674
0
votes
4 answers

What is the use of a C++ class containing an "implementation" and "interface" pointer to itself?

I'm studying some source codes and I'm just wondering why a class (or classes) is often implemented this way: class EventHandler { ... EventDispatcher* m_Dispatcher; virtual bool ProcEvent( EventHandler* Sender, int Task, int Event, void*…
jasonline
  • 8,646
  • 19
  • 59
  • 80
0
votes
2 answers

Dealing with a null sub object in a class?

I have several classes public class Person { public int Id{get;set;} public string Name{get;set;} public virtual Institution Institution{get; set;} } public class Institution { public int Id{get;set;} public string…
John S
  • 7,909
  • 21
  • 77
  • 145
0
votes
1 answer

Calling a static/shared method from a non-static/shared methd, good or bad?

Let's say for instance I have a class set up as such: Class Foo Private instanceVariable As Integer = 2 Public Shared Function Bar(ByVal localVariable as Integer) As Integer Return localVariable * 2 End Function Public…
Josh Braun
  • 490
  • 2
  • 16
0
votes
1 answer

First GUI, app organization

This is my first java swing application and I have some questions about the organization. I need to create a application that after log in redirect the user to (let's call it) "Normal user page", "Admin Page" or "Super user page". After reading some…
0
votes
1 answer

class diagram Composition Relationship

Should the owner have an attribute of the owned object type in a class diagram composition relationship? Or is having a key or related property considered a composition, too? My example is: I have two classes "user" and "image". The user logically…
MohamedAbbas
  • 1,149
  • 4
  • 15
  • 31
0
votes
4 answers

Best way of class design in Java: An example

Which is the best design for the below problem description : A 'Student' has 4 Pens of colors Blue, Red, Green and Orange. Here is Pen class- Class Pen{ String color; //Getters & setters public write(){ // Write some thing using…
Sanjeev
  • 425
  • 10
  • 17
0
votes
0 answers

Outside class or nested class?

I have a class as following: public class A { public string P1 { get; set; } public string P2 { get; set; } public B b = new B(); public A() { b.B1 = ... b.B2 = ... } } Where class B is outside (not nested)…
tesicg
  • 3,971
  • 16
  • 62
  • 121
0
votes
1 answer

How to define base class that handles database connection?

I have a console application with a base class as following: public abstract class PaymentSystemBase : IPayable { private SqlConnection _connection; protected PaymentSystemBase() { CreateDatabaseConnection(); } …
tesicg
  • 3,971
  • 16
  • 62
  • 121
0
votes
4 answers

Class design: clearing state

I am designing a class library which will be used like this: Engine eng = new Engine(); eng.AddPart(part).AddPart(otherPart).Run(); The problem with the class is that the parts are kept by the engine so if you want Run it with some other parts…
Giorgi
  • 30,270
  • 13
  • 89
  • 125
0
votes
3 answers

How should I refactor my class?

Basically I have a class that sends a SOAP request for room information receives a response, it can only handle one room at a time.. eg: class roomParser { private $numRooms; private $adults; private $dailyPrice; public function…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
0
votes
2 answers

Should a Form object posses the dual responsibilities of displaying and processing?

I have a prototype with a Form class which auto-generates an HTML form, and now I am plugging some processing functionality into the prototype. Should the same Form class that generates the HTML for the form also process the form? Doing so would…
Chad Johnson
  • 21,215
  • 34
  • 109
  • 207
0
votes
3 answers

Inheritance with composition

I am designing a system, I have not yet implemented first I am just diagraming it and then will code it, I want to ask one simple question: What to do when we are using both inheritance and composition at the same time? For example, in a hotel,…
user3215228
  • 313
  • 1
  • 3
  • 13
0
votes
4 answers

Use class level field or method variable?

I have a object I initialize in a method like : public void something() { Dummy obj = Factory.getDummy(); method2(obj); } now, this Dummy object is to be used by many methods public void method2(Dummy obj) { method2(obj); …
codingenious
  • 8,385
  • 12
  • 60
  • 90