Questions tagged [class]
A template for declaring a type of object.
304
questions
-2
votes
1
answer
168
views
What is a component in C#?
Introduction
Components are an important building block of software. In terms of software architecture, there are a lot of principles regarding components that should be adhered to (high cohesion, low ...
0
votes
4
answers
155
views
Resolving Dependency Cycles
Class and component dependency cycles
Assume, we have component A with class CA, and component B with class CB, with a cyclic two-way dependency between classes CAand CB. Hence, we have a cyclic ...
-2
votes
1
answer
129
views
Defining functions inside vs outside a class
Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
1
vote
1
answer
132
views
Can a standalone class be seen as violating the Liskov Substitution Principle
Say we have the interface
interface IColoredSquare
{
int GetSideLength();
void SetSideLength(int length);
string GetColor();
}
and I implement it like this
class ColoredSquare : ...
2
votes
1
answer
572
views
In python when is absolutely preferable use a class than a module?
Python is the language I use most in this period.
My background in Java
Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
2
votes
3
answers
151
views
Which association should be in the class diagram
there are a vehicle class and customer class . In short, in the customer class there is a function that shows 'can this person or company rent that car'.The function uses a object of vehicle and ...
0
votes
5
answers
1k
views
Comparing Java objects with different member variables
I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList ...
1
vote
2
answers
396
views
How to design an entity that has different fields depending on a type?
I have a specific domain entity that has a given type and some attributes. Based on the type, it can have another set of type-depending attributes. Normally, I would create a class for each type and ...
2
votes
2
answers
144
views
What is the threshold of "usage" of a parent class member that should move to child class?
For example, for base and child classes, if all child class need a class member, eg: baseHp, which represents the base hp to calculate the actual hp of monsters in a game:
public class Monster{
...
0
votes
1
answer
111
views
Assigning to fields in function or by function?
While writing the constructor for class A in Python, I calculate some of the class's fields using function fun(). This function is never used outside the constructor of instances of this class.
In ...
2
votes
3
answers
543
views
Why do we need factories in the first place?
I went through various blogs but nowhere I can find the reason of having virtual constructors in C++.
Why is virtual constructor needed and lets say if we go through the wrong way of creating virtual ...
1
vote
0
answers
87
views
Mimic public/private data members in C with hidden static arrays
Context
I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant.
It is the ...
9
votes
4
answers
4k
views
How to analyze and understand the use/application of a "class" in a colossal million-line legacy code base?
I am working on a huge code base (more than a million lines of code with a sophisticated architecture) written in C++ over the span of a couple of decades. The task on which I'm working at this point ...
-2
votes
2
answers
422
views
How does injecting a concrete class expose implementation? [duplicate]
I've read that you should pass in an interface instead of a concrete implementation so that the consumer doesn't need to know anything about implementation details.
I don't understand how injecting a ...
1
vote
1
answer
294
views
Can I separate methods into different classes by passing in constructor properties from one class to another?
I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare ...
-1
votes
2
answers
165
views
Should I make a HotelList class?
This question has always bothered me I am finally ready to ask it out here.
I am creating a hotel reservation app, and I am in the phase of deciding what classes I will have. Among classes such as ...
8
votes
4
answers
1k
views
Are there advantages to using an interface, rather than a class, for a Java application?
Java is often (rightly IMHO criticized) for overusing the class keyword, as it can denote:
a factory to instantiate objects (traditional classes)
a collection of global methods (when all methods are ...
0
votes
1
answer
182
views
Good class design: dependency vs duplication? [closed]
Let's say we have a class( My_Func_Dec ) that models a 'function header declaration' as it might appear in a .h file.
const std::string func1 ( const std::string& arg1_, const std::string& ...
1
vote
3
answers
3k
views
Is it possible to instantiate a template class at runtime?
Suppose I have two abstract classes called Color and Animal
And I can create classes Green/Red/Blue derived from Color and classes Dog/Cat/Pig derived from Animal at runtime using factory pattern.
...
0
votes
1
answer
226
views
Verbs in Use Case name "Create User" [closed]
I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what ...
3
votes
2
answers
405
views
Accessing properties from embedded objects as attributes of container class
In Python, I have a class C which embeds objects from classes A and B. Is it considered good practice to creates shortcuts from the properties of embedded objects of classes A and B as attributes of ...
0
votes
1
answer
116
views
Time consideration in multiplicity of classes
In the following image, regarding a CD shop that rents its music CDs.
My question is regarding the correct multiplicity of X. I can think of several possibilities for X:
X= 1..1 as each copy of ...
27
votes
9
answers
8k
views
Is it a security vulnerability to declare class members as public?
I have always wondered whether public, protected, and private has security implications post compilation.
Hypothetically:
class Foo
{
public:
int m_Foo; // Completely vulnerable and dangerous
...
2
votes
2
answers
356
views
Actors and their representation in the system
I am trying to understand the relationship between actors and their representation in the system. Please see the below figure
In the figure on left, I have an abstract representation of my system. In ...
2
votes
5
answers
1k
views
Class method Vs. Interface?
I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way".
I have a few ...
-2
votes
1
answer
675
views
Should customer class have the different function or should i include it in account class in my UML class diagram of banking system?
Should i include the different functions of open account, close account , withdraw in the customer class(as shown in the picture) or should i include it in the account class
0
votes
1
answer
875
views
Appointments using time slots
I would like to create a dynamic appointment system between teacher and student to easily allow them to make an appointment.
In this system, teachers select their 30 minutes time slot availabilities ...
-2
votes
1
answer
944
views
Appointments Booking Using Slots
I'm looking for an efficient way to create appointments between teachers and students.
I want teacher to be able of make their students know their availabilities : For example, A Teacher writes on the ...
0
votes
0
answers
715
views
Why does Protobuf generate outer classes for Java?
I googled this and found questions like "How to use Protobuf message as java class without a java outer class?" (https://stackoverflow.com/questions/60312156/how-to-use-protobuf-message-as-...
1
vote
1
answer
378
views
Creating an attribute of an object versus a method in the class
This question pertains to properly structuring a class. The object of a class I have is instantiated with multiple parameters. Many of these parameters are then manipulated with each other to derive ...
0
votes
2
answers
97
views
Why doing more than one thing in a class is sometimes valid? [duplicate]
classes and method should do one thing like the code below:
class A {
public int a() {
b();
}
private int b() {
c();
}
private int c() {
}
}
The code mentioned below I found it ...
0
votes
3
answers
125
views
What approach is commonly used when a generic object needs to be converted into a specialized object?
Let's say I have an instance of a superclass and at a later stage this object needs to be converted into a subclass instance (based on additional information that are stored in the object).
Is it ...
-1
votes
3
answers
397
views
How to reduce the number of classes in a project?
i'm trying to design a game program, but when thinking about which objects to introduce there seems to be far too many.
For example for main object "Player" there are a lot of peripheral ...
1
vote
2
answers
345
views
Can and should constructors do more work than merely assigning values to fields? [duplicate]
A typical introductory example to OOP, classes, and constructors is object Car, with properties such as float fuel, bool is_engine_running, etc etc, and a class and constructor definition might be as ...
1
vote
2
answers
376
views
using-declaration or typedef for iterator tags?
I'm creating a class representation of a mathematical tuple (or simply, an ordered set of numbers). Being a list-like object that could benefit from an iterator representation, I have decided to give ...
9
votes
3
answers
6k
views
Is it best practice to define a member function directly in a class?
I'm a beginner in C++, and I was wondering if it is best practice to define a member function directly in a class, such as:
// something.hpp
class C {
inline int func() { return ... ; }
}
rather ...
-1
votes
3
answers
389
views
What are the differences between Class Oriented Design and Object-Oriented Design?
I saw an answer on SO which said that just having a class with methods doesn't make it OOP and that it represents Class Oriented Design.
I'd like to hear the differences between Class Oriented Design ...
-1
votes
3
answers
1k
views
Does wrapping functions/'things' in classes reduce efficiency?
I was reading some C++ object-oriented programming notes that mentioned that we should avoid wrapping functions in classes if it is not required, since wrapping 'things' in classes would reduce ...
1
vote
0
answers
122
views
Is using C++ Classes to handle commonly used parameters a misuse of classes?
My team works on an HTTP web server in C++. The codebase has aged over time, and has a widespread problem of 12+ parameters being passed to every function.
A fake example: We need to build a Car, but ...
5
votes
4
answers
373
views
How to deal with different level of abstractions (blurred line between data and models)
My question is about the way to represent data models created at runtime.
To illustrate, let's say we would like to create a CMS-like app in which end-users may create custom forms.
Those forms are ...
0
votes
3
answers
73
views
"Assign" Role Association between two classes
If there is Class A and Class B and there is an association that B can be assigned to A.And the multiplicity is 1:M or M:1 from A to B.Example:
1.Room has Collection of Keys, and Key can can assigned ...
2
votes
3
answers
513
views
Enums or Multiple Inherited Classes
I am reading about OOD and came across Parking lot design problem.Parking lot has parking floors which has parking spots.The parking spot class looks as follow:
public enum ParkingSpotType {
...
2
votes
0
answers
34
views
Update class member gradually [duplicate]
Consider the following:
import typing
class MyClass(object):
def __init__(self):
self.my_member: typing.Optional[dict] = None
def update_member(self):
self.my_member = {}
...
1
vote
4
answers
1k
views
Why have separate keywords for 'extends' and 'implements' in Java? [closed]
Short answer that I've come to accept:
Firstly, it helps with readability, being able to see which is the superclass apart from interfaces. Secondly, though 'extends' and 'implements' do the same ...
1
vote
2
answers
155
views
Going from Javascript to C++. I have teacher and student objects, and I want to display if they are teachers or students. How should I do this?
This may be too general of a question, but basically whenever I try to find an answer for something that would work from a Javascript approach, the answer heavily implies that you wouldn't do it that ...
1
vote
2
answers
369
views
Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface?
Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface (if such implementation is even possible)?
0
votes
2
answers
4k
views
Terminology: Classes that contain only methods [closed]
I am studying the programming language Kotlin, and I just came across the idea of a Data Class. I have a background in Java programming where classes can have fields and methods. I have heard ...
0
votes
1
answer
152
views
How to deal with metaclasses in strong-typed language : is it ok to mix classes and metaclasses?
I'm working on a programming language design ans I'm struggling with how I should type the concept of Class.
Let me show you some code to illustrate my problem :
class MyClass
{
}
function ...
11
votes
1
answer
2k
views
Why List<T>.Enumerator is struct?
During my investigations of List<T> enumeration I noticed List<T>.Enumerator is struct. In opposite for instance to System.Array.SZArrayEnumerator or System.SZArrayHelper....
-3
votes
1
answer
133
views
How do I find out all modifications made by installing software? [closed]
So I want to find out how to get a list of all modifications made by installing a piece of software.
For example. If I install Word, I want to see all directories created, classes registered, dlls,
...