Questions tagged [class]
A template for declaring a type of object.
294
questions
0
votes
1
answer
60
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
304
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
82
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
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 ...
-2
votes
2
answers
224
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
155
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
160
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
502
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
159
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& ...
0
votes
3
answers
2k
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
119
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
263
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
107
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
236
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
938
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
473
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
586
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
769
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
524
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
172
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
92
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
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 ...
-1
votes
3
answers
322
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 ...
0
votes
2
answers
132
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
255
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
5k
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
318
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
951
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
117
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
364
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
70
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
303
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
782
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
154
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
339
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
3k
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
144
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
84
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,
...
-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 ...
-1
votes
2
answers
121
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 ...
0
votes
1
answer
85
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 ...
-1
votes
1
answer
2k
views
Why would you make a struct without typedef?
Since I cut my teeth on code with OO, I’m biased toward using structs as classes without methods. However, there’s probably a good reason that typedef isn’t the default behavior of struct. What is it?
5
votes
3
answers
1k
views
Struct or class for wrapping an int when 0 isn't a valid value
I have a business object which is basically a wrapper around a value of type int. There are some constraints for the value/object:
Not every value in int's range is valid1
The valid values are not a ...
0
votes
1
answer
380
views
Responsibility-driven design
I am quite confused about the responsibility-driven design concept. Mainly because of ever so slightly changing definitions depending on the source.
Quoting BlueJ (the book I am learning that teaches ...
-2
votes
4
answers
353
views
Is judicious & plausible selection of class fields a valid refactoring step?
I'm a great fan of refactoring but I've been wondering about the issues raised by refactoring.
Fowler advises refactoring
to make code readable to all users
to make the code structure more sensible, ...
29
votes
9
answers
10k
views
In OOP, isn't the 'protected' keyword required?
Some modern languages (e.g. Swift, Dart) do not support the protected access modifier keyword. Swift is a protocol-oriented language, but I've heard that Dart is a completely object-oriented language.
...
-2
votes
2
answers
391
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 ...