Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [class]

A template for declaring a type of object.

2
votes
2answers
169 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
96 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
154 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
191 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 ...
-4
votes
3answers
65 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
201 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
133 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
87 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
152 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
91 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
84 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
148 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
119 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
166 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 ...
4
votes
3answers
380 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
85 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
356 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
259 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
146 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
69 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
68 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
244 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
61 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
56 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
146 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
237 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
4k 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
3k 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
245 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
281 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....
5
votes
3answers
13k 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
342 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
432 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
322 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
112 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
174 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 ...
-6
votes
3answers
166 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 ...
4
votes
1answer
818 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 ...
5
votes
3answers
18k 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 ...
3
votes
1answer
321 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
1k 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
1k 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
555 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: ...
3
votes
4answers
96 views

Structure when I need multiple “copy” instances of a common base class?

So I'm building a card game where each card has cost, damage, and durability, as well as name and description. Obviously one would think of creating a Card class: class Card { int cost int ...
2
votes
2answers
83 views

Creating an Instance of a Complicated Class

How do I create instances of classes which require a huge amount of components and attributes? Take for example a car. A car has hundreds of sub components each with their own specific properties. ...
10
votes
5answers
763 views

What is a good design practice to avoid asking a subclass type?

I've read that when your program needs to know what class an object is, usually indicates a design flaw so I want to know what is a good practice to handle this. I'm implementing a class Shape with ...
5
votes
5answers
442 views

Should I encapsulate an object inside another object as methods or just access it directly?

Suppose I have a class A: public class A{ public void a(){ } } and class B use A: public class B{ private A a; } Should I encapsulate A in B: public class B{ private A a; ...
1
vote
0answers
118 views

Should all classes and interfaces ultimately derive from one Class, and how does this affect type safety?

If I have "Object" as the top level class, then I have various interfaces, ISomething, ISomethingB, ISomethingC, then I have Class x,y,z, all ultimately deriving from the class Object (these ...