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.

-1
votes
2answers
115 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
75 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
128 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
81 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
79 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
23 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
142 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
118 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
155 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 ...
0
votes
0answers
66 views

Is subclassing the way to go if I just want to add one method?

My question is Python-specific. Let's say I am working with an object from a Python third-party library. The object takes some arguments and generates HTML content. The object also has a save method ...
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
354 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
203 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
129 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
68 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
64 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
237 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
58 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
55 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
140 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
218 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
3k 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
244 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
262 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
10k 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
335 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
426 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
304 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
173 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
163 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
788 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
13k 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
301 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
472 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
82 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
722 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
398 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 ...
2
votes
2answers
107 views

Keep consistency when items can be in several classes

I'm having a difficulty to figure out relating an item to classes properly. For example, I have a business directory website that shows profiles of different companies according to the products/...
-1
votes
1answer
123 views

How to quickly work on a single class of a big GUI C# project?

So here's the problem. I have a massive C# project in Visual Studio. It has a big GUI that manages a large number of classes. In one of the form windows, there is a bunch of textboxes. The user fills ...
-2
votes
1answer
184 views

How does accessing class level variables in java work?

I'm doing my third online course in learning java because I couldn't get over how to even start a project from scratch. There was a lesson in this new course that made me ask this question of the code ...
0
votes
2answers
106 views

Using a class for a collection element, with methods to access other collections

I'm hoping for a sanity check in my design thinking. I'm working with a small team on a website based on a MongoDB database. There are several collections in the DB -- for example, one representing ...
-1
votes
1answer
125 views

Memory override using classes when using lists in python

I am trying to create a new variable with class Lamb (called hold) using a variable (main), which also has class Lamb. Lamb has two parameters (x and y). I create a variable called main with class ...