Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [class]

A template for declaring a type of object.

Filter by
Sorted by
Tagged with
1 vote
1 answer
114 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 : ...
user avatar
2 votes
1 answer
274 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 ...
User051209's user avatar
2 votes
3 answers
137 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 ...
Tunahan's user avatar
  • 31
0 votes
5 answers
612 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 ...
Delta88's user avatar
  • 19
1 vote
3 answers
242 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 ...
Fischer Ludrian's user avatar
2 votes
2 answers
141 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{ ...
wcminipgasker2023's user avatar
0 votes
1 answer
82 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 ...
Harm van den Brand's user avatar
2 votes
3 answers
411 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 ...
H Kumar's user avatar
  • 31
1 vote
0 answers
85 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 ...
Sam's user avatar
  • 31
9 votes
4 answers
3k 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 ...
Dude's user avatar
  • 207
-2 votes
2 answers
356 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 ...
james's user avatar
  • 113
1 vote
1 answer
216 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 ...
Kevin Greetham's user avatar
-1 votes
2 answers
162 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 ...
multigoodverse's user avatar
8 votes
4 answers
979 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 ...
Ray Toal's user avatar
  • 1,315
0 votes
1 answer
177 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& ...
Mote's user avatar
  • 9
0 votes
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. ...
Xie Qing's user avatar
0 votes
1 answer
186 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 ...
Carlos Figueroa's user avatar
3 votes
2 answers
369 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 ...
Daniel Arteaga's user avatar
0 votes
1 answer
114 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 ...
Karl 17302's user avatar
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 ...
Anon's user avatar
  • 3,613
2 votes
2 answers
346 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 ...
Afia R. S.'s user avatar
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 ...
adc395's user avatar
  • 39
-2 votes
1 answer
640 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
Moaaz Siddiqui's user avatar
0 votes
1 answer
806 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 ...
anthonya's user avatar
  • 109
-2 votes
1 answer
917 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 ...
anthonya's user avatar
  • 109
0 votes
0 answers
660 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-...
Matt Welke's user avatar
1 vote
1 answer
267 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 ...
matsuo_basho's user avatar
0 votes
2 answers
96 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 ...
Sajied Shah Yousuf's user avatar
0 votes
3 answers
124 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 ...
MaxxOr's user avatar
  • 67
-1 votes
3 answers
370 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 ...
r0k1m's user avatar
  • 851
1 vote
2 answers
256 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 ...
SRSR333's user avatar
  • 325
1 vote
2 answers
340 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 ...
Angel E.'s user avatar
  • 119
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 ...
Angel E.'s user avatar
  • 119
-1 votes
3 answers
366 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 ...
jeffbRTC's user avatar
  • 167
-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 ...
The Pointer's user avatar
1 vote
0 answers
120 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 ...
DonutGaz's user avatar
  • 251
5 votes
4 answers
370 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 ...
ibi0tux's user avatar
  • 241
0 votes
3 answers
71 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 ...
rahul sharma's user avatar
2 votes
3 answers
459 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 { ...
rahul sharma's user avatar
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 = {} ...
Spack's user avatar
  • 129
1 vote
4 answers
996 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 ...
xtratic's user avatar
  • 456
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 ...
sheepdeets's user avatar
1 vote
2 answers
357 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)?
Steve's user avatar
  • 119
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 ...
Steve T's user avatar
  • 141
0 votes
1 answer
150 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 ...
ibi0tux's user avatar
  • 241
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....
Yarl's user avatar
  • 288
-3 votes
1 answer
113 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, ...
lakersfan's user avatar
-2 votes
3 answers
3k views

Accessing one class variable from another class in C++

Suppose I'm in some function of class A, in this function I define an object of class B, say b, and call some function using b.func() which updates some values and arrays, say x and A. Then, I create ...
Alex Z's user avatar
  • 1
-1 votes
2 answers
124 views

Do I name classes based on the object type they represent or the responsibility they have?

The more I read about the Single Responsibility Principle the less I see a class as an object type, but rather as a servant that does something. For example, let us suppose we have a new requirement ...
Andy Gondzer's user avatar
0 votes
1 answer
87 views

Inheritance but with two different shared traits?

I am facing a dilemma with designing an api gateway. Currently, I am using the pipeline pattern, with different stages being the requests made to various services, (http, sockets, amqp, ...). I have ...
hotswappable's user avatar

1
2 3 4 5
7