Questions tagged [class]

A template for declaring a type of object.

Filter by
Sorted by
Tagged with
-2
votes
2answers
102 views

C# Static & Constructor Logic [closed]

I learn C# and try to understand the logic between static and Constructor right now. One thing I need ask you about an example which I will give at below. (please ignore the quality of code or how ...
-2
votes
1answer
154 views

UML class diagrams - how do I draw a class diagram that shows a self-reference? [closed]

So I have the following case. I have an interface A and an implementation AImpl. Now I have another implementation of A, called A2Impl, which references any instance of A besides implementing A ...
0
votes
1answer
142 views

Class structure: How should a binary tree and it's node class be implemented in Java in terms of class files?

In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTreeclass, or should it be a default class in the same class file as the BinaryTree class?...
1
vote
4answers
134 views

Should supporting algorithms be in their own class?

My Widget class has a method called loadWidget. This method needs to shuffle an array to work properly, among other things. In Widget, I could implement a Fisher-Yates shuffle as its own static method ...
0
votes
2answers
124 views

2 way multiplicity constraints in code

my goal is to convert this class diagram into Java code. How should I approach this, given that I want the constraints to hold at all times? It creates a chicken-egg problem where the first Course or ...
2
votes
2answers
185 views

How to organize my test functions? (Part II: Keepin' it classy)

What are the best practices to organize your unit tests in classes? I see different possibilities: 1) One would be to write one "container" class for each function you want test and then ...
0
votes
2answers
102 views

Where should the logic concerning a class's behavior reside? In the class itself or in the calling subroutine?

I have a car object. The car cannot be driven unless it is turned on. When should I check to see if the car is on before I try to drive it? In the main program? class Program { static void Main(...
1
vote
2answers
167 views

Why are classes named “class”? [closed]

Could it also have made sense to call it a "Form", as in the Platonic sense of the ideal form that represents the thing which earthly objects strive to emulate?
0
votes
2answers
203 views

Which option is good in terms of software design?

I have one request interface IRequest and two classes ClientAddress and ClientOrder are implementing it. The same design is followed for Response with inteface IResponse and classes ...
-3
votes
3answers
100 views

Java - OO - Understanding Subclass of Class Object

While a fundamental concept, I don't understand the statement "every CLASS in Java is a subclass of the class object," which is often quoted in JAVA tutorials usually in the inheritance section. I ...
1
vote
1answer
257 views

How many test-cases need to be created at least (valid and invalid equivalence class)?

Assume there is any program that is supposed to be tested and you like to perform an equivalence class analysis on it. Let's say you identified six valid and four invalid equivalence classes. Then, ...
0
votes
2answers
249 views

What are the advantages of proxy classes?

I've been learning about proxy classes in c++. I really don't see the advantages of using proxy classes, as they're not any better at concealing information than private members are. What advantages ...
-4
votes
1answer
158 views

Inheritance of Constructors from parent into child class [closed]

Is the Default Constructor of Super or Parent class Can be Inherited into Child class ?
3
votes
3answers
448 views

Factory pattern or builder pattern ? which one is suited for reading Finite Element Model data from a text file?

A follow up to another question (Making a design decision about reading model data from an input file). I wish to ask another question regarding builder or factory pattern. (I read that builder is ...
2
votes
1answer
103 views

Making a design decision about reading model data from an input file

I am writing a finite element software in C++ and Qt. I want to load the input data to the model. I have a Model class that holds the data and does the work. I have created a simple lexer and parser ...
-1
votes
3answers
622 views

Multiple classes working on an object

This might be a bit of a wide question but I want to understand if it's the correct way to do it. Assume I have a couple of classes all doing operations on an object. First class takes the object, ...
-2
votes
1answer
25 views

Data Sharing Levels of Privacy

I've been looking through class and friends and similar c++ arrangements to share data, and cannot find how to program levels of share. No players can know what the other players have in their gold-...
0
votes
3answers
153 views

Java, pattern to restrict field usage in subclasses to after calling specific method

I want to extend class Base which is defined in specific API and the extend the extended again. As you can see below, draw method of intermediate class calculates variable top and I need to use it in ...
0
votes
2answers
120 views

Using new [className] without a return

I have started using the following in my automation code in instances where I'm not interested in keeping the object 'alive'and just using it as a means as a type of precondition. For example: ...
3
votes
1answer
200 views

What's the best way to handle a large multi-file class in Javascript?

I have a very large class of 59 methods and about 3000 lines of code. I know that's far larger than most people would want, but the class represents a virtual machine, and most of the methods are run ...
5
votes
4answers
604 views

Proper way to name a class which has just methods and not fields

GOAL: naming a class which has the responsibility to save data in Android database. The class structure is like this ClassName { public void saveSync(...){ /* implementation*/ } public ...
1
vote
1answer
89 views

An interface for designing Arduino code

Often I want Arduino board to control several peripherals. Writing program for all of them in one document using #define SOME_PIN 4 constructions seems pretty inconvenient to me. Especially in such a ...
1
vote
3answers
363 views

When to use Parameters and When Not to C#

I am have an application using MVVM pattern. It takes a user ID and returns a table with the user's bookmarks. I am trying to decided if it is better practice to include parameters in my model's ...
3
votes
5answers
2k views

Use POJO or Map when there is a finite number of known keys?

I have some set of data with key-value pairs, but there is only a finite and known set of keys, all of the key should always be present on that data, and they all have the same type for the value. ...
-1
votes
1answer
187 views

Does Interface Segregation Principle apply to parameters/request objects?

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a ...
-2
votes
1answer
76 views

What to name my config classes

What name should I give classes which are just for configuration? For example, when using JAX-RS, every application is required to have an Application class which extends the superclass javax.ws.rs....
0
votes
1answer
79 views

Ext JS: Designing a base class and override it

I'm trying to define a base class and override it's items on different inherited sub-classes. I'm following MVVM pattern to fetch records from backend. Created several stores and formulas within ...
7
votes
1answer
264 views

Should every method in a class be defined in an implemented interface?

I can see how interfaces are very useful to force different classes to have the same functionality. But there are also actions that are bound to a specific class (like updating an unique variable ...
0
votes
1answer
65 views

PHP User, Customer, Business Relationship

I am creating an invoice management system that has a User Class that handles the login system. Currently each User is associated with a Customer and the Customer class handles obtaining Monthly ...
1
vote
0answers
60 views

Program and Class Design

I am hoping you may be able to give me some advice on class design and what would be best for the program I'm currently writing. This is being done in Java and the goal is to generate letter data ...
0
votes
4answers
159 views

How to insert code in a method in a derived class [duplicate]

I have a base class with a method called Update: Start Update Code block 1 (An If statement) Code block 2 (Setting a variable based on the If result) Code block 3 (A switch which is ...
1
vote
1answer
315 views

UML - Design Class Model diagrams

I have several questions about UML diagrams as I am not finding them very clear (they are new to me). 1) When making a diagram with generalizations/specialization: if I do not have all of the ...
7
votes
4answers
6k views

Using vectors of shared pointers to objects in my C++ code to prevent object duplication

In my C++ project, I have three classes, Particle, Contact, and Network. The Network class will have N particles (std::vector<Particle> particles) and Nc contacts (std::vector<Contact> ...
10
votes
5answers
4k views

How to resolve class interdependence in my C++ code?

In my C++ project, I have two classes, Particle and Contact. In the Particle class, I have a member variable std::vector<Contact> contacts which contains all contacts of a Particle object, and ...
1
vote
1answer
250 views

Should I be creating more objects in Java?

I am very new Java and have been messing around with a program that essentially prints a random line of characters based on random char values and array manipulation. I am having a lot of trouble ...
0
votes
2answers
336 views

Dynamically choose whether to use __slots__ in a class

I've got a generic container class: from typing import Container, Generic, TypeVar, NamedTuple import sys fixed_typing = (sys.version_info >= (3, 6, 2) or (3, 5, 3) <= sys....
15
votes
3answers
21k views

How to best to organize class and interface files?

OK .. after all the discussion I'm changing my question slightly to better reflect a concrete example that I am dealing with. I have two classes ModelOne and ModelTwo, These classes perform ...
2
votes
2answers
392 views

Is “A programmer-defined type.” a right definition of “class” in Python?

In Think Python 2e "class" is defined as "A programmer-defined type. A class definition creates a new class object." But isn't a built-in type considered a class too? Using Python 3.4.0, the ...
7
votes
4answers
443 views

Encapsulation and Displaying Information

This site and SO contain many pages about getters/setters and if they break encapsulation or enforce it. My question is for those developers that agree that getters/setters break encapsulation and ...
0
votes
1answer
386 views

Instantiate a class from a config file. Where should the parse function go?

I have a class in python that is instantiated from the values of a (json) config file. I was wondering what is the best practise to do that (if there is a best practise and is not just a matter of ...
1
vote
1answer
116 views

Isn't it redunant to declare package in the class file? Can't it be inferred from the build path?

I have class Foo, its first line reads package com.bar.something.baz. Its file is in /com/bar/something/baz/. Why do I have to declare the package in the class file and then put the file in the same ...
1
vote
3answers
127 views

Everthing in a class/classes or just part of the program?

I wanted to move my program into a class or classes because most of the form post I read say it makes the program easier to read, understand the flow of the code, and improve maintainability. ...
3
votes
4answers
176 views

Is there any technique to help in deciding where a certain functionality belongs?

In Object Oriented Programming, since we use classes and methods in these classes, when we are going to implement a certain functionality we must decide where it belongs, in other words, on which ...
-5
votes
3answers
172 views

Why solve a problem with a class and not a function?

I am a new to in programming, especially to C++. At first I learned how I make functions (it was amazing). But now that I've learned about classes (and objects) I am so confused... when I should use ...
3
votes
1answer
924 views

Association + multiplicity vs aggregation and composition?

I know the differences between these associations (as described here). However I'm wondering: Composition, why not simply use an association with multiplicity of 1..* (and thus implicit saying that ...
6
votes
3answers
32k views

Is there a better way of using getters and setters on private members of a class?

I have this example class: public class Carrots { private string name; public void SetName(string pName) { name = pName; } public string GetName() { return ...
2
votes
1answer
428 views

Representing hierarchical data (C++)

Say we have 2 Classes: Account and Contact like this: class Account { string Id; string Name; } class Contact { string Id; string FirstName; string LastName; } An account can ...
0
votes
3answers
2k views

Why do the following enum fields extend their base class or base enum?

Regarding enums in java how I understood is Sample enum public enum Strategy { STRATEGY_A { @Override void execute(){ System.out.print("Executing strategy A"); ...
4
votes
2answers
2k views

How should libraries be shown in UML class diagram?

Maybe the title isn't that clear so I will explain this a little bit further. I use biojava to perform BLAST searches. However this BLAST.jar contains a lot of classes: org/biojava/bio/program/...
1
vote
0answers
802 views

Should I use a closure instead of a class when I only have one method?

Lets say I have a JavaScript class that takes a whole lot of settings in the constructor, and then only have one method that the user of the class might want to call multiple times. Here's an example: ...