Questions tagged [class]
A template for declaring a type of object.
283
questions
0
votes
1
answer
74
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
89
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
96
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
7k
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
63
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
515
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
158
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
164
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
247
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
217
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
60
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
81
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
120
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
231
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
85
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
119
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
3k
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
278
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
345
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
110
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
329
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
66
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
220
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
579
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
148
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
258
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
1k
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
126
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 ...
9
votes
1
answer
1k
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
73
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
1k
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
113
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
78
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
1k
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
647
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
275
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
349
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
9k
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
180
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 ...
-2
votes
1
answer
575
views
UML class diagrams - how do I draw a class diagram that shows a self-reference? [closed]
So I have the following case. I have an interface A and an implementation AImpl. Now I have another implementation of A, called A2Impl, which references any instance of A besides implementing A ...
0
votes
1
answer
1k
views
Class structure: How should a binary tree and it's node class be implemented in Java in terms of class files?
In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTreeclass, or should it be a default class in the same class file as the BinaryTree class?...
1
vote
4
answers
166
views
Should supporting algorithms be in their own class?
My Widget class has a method called loadWidget. This method needs to shuffle an array to work properly, among other things. In Widget, I could implement a Fisher-Yates shuffle as its own static method ...
0
votes
2
answers
392
views
2 way multiplicity constraints in code
my goal is to convert this class diagram into Java code.
How should I approach this, given that I want the constraints to hold at all times? It creates a chicken-egg problem where the first Course or ...
2
votes
2
answers
205
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
2
answers
106
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
2
answers
503
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
2
answers
212
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 ...
-3
votes
3
answers
377
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
1
answer
589
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, ...