object oriented - What is the best way to make a collection of functions available to a whole program in c++?

I am currently working on a voxel (Minecraft-like) engine in C++. Almost all of the code (ie. world generation, rendering, user input) needs to access data about the block types. To accomplish this, I created a BlockRegistry class with member functions to register and access BlockType instances. Each BlockType instance has member functions to access all of it's properties (ie. textures, shape). The problem I am having is making sure that all parts of the code have access to this class. Right now, I am passing around a pointer to it, but this in...Read more

object oriented - DDD Injecting Services on Entity Methods Calls

Short format of questionIs it within best practices of DDD and OOP to inject services on entity method calls?Long format exampleLet's say we have the classic Order-LineItems case in DDD, where we have a Domain Entity called an Order, which also acts as the Aggregate Root, and that Entity is comprised not only of it's Value Objects, but also a collection of Line Item Entities.Suppose we want fluent syntax in our application, so that we can do something like this (noting the syntax in line 2, where we call the getLineItems method):$order = $order...Read more

php - Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code belowMyController //MyAction //MyHandler{ public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); // ... }}Should such code be refactored to use dependency injection instead? If so, for what objects? All of them? Are there exceptions to which objects can be instantiated and ones that cannot? MyController //MyAction //MyHandler{ public function __construct(MyObjectClass $myObject) { $this->myObject = $myObject; } public func...Read more

object oriented - How to output exception messages in GUI applications in order to decouple application code to GUI code?

I want to make GUI applications such that the non-GUI code is independent from the GUI one (let's say I'll use Java 8 and Swing for example). The goal is that I could hypothetically change the GUI API/library, or the kind of UI, for example shifting from a GUI to a console output, without modifying the non-GUI code (also in observance of the Open/Closed principle). In particular, my question is about how to handle exception messages so that they can be output to any UI: let's say that I have try/catch blocks in my non-GUI code, like this (in t...Read more

object oriented - If an enum is used without bitwise operation, and all of its values are predefined individually, is it violating open closed principle?

For example, if I use an enum, which all values are manually defined individually, for example:public enum MyNum{ Zero(0), One(1), Two(2); private final int value; MyNum(int value){ this.value=value; } public int getValue(){ return value; }}public class Test{ public static MyNum getUnknownMyNum(){ return MyNum.Two; } public static void main(String[] args){ MyNum n1=MyNum.One; MyNum n2=MyNum.Two; System.out.println(n1==getUnknownMyNum()); System.out.println(n2==get...Read more

Object Oriented Design - Genome Class / Mutation Class

ContextI am having an argument with my friend on how to start implementing a Genetic Algorithm called NEAT (NeuroEvolution of Augmenting Topologies).Method 1I am arguing in favor of having two classes, one for Genome and one for Mutation. This Mutation class will provide methods for mutating genomes by taking a genome as input and returning a mutated genome. Furthermore, this implementation will have classes for each process like Selection, Crossover etc.ProsThis way we will have the option to derive from Mutation class later on to implement va...Read more

object oriented - OOP - Is this data hiding?

I've been reading about data hiding and there seem to be slightly different definitions of it, so when trying to come up with a practical example, I'm not sure if I'm doing the right thing.So far, I got that data hiding protects data from being accessible in an unexpected way. This makes me think of two different cases, but I'm not sure if these actually describe data hiding or I'm describing something else:Let's say I have a Gym class and a Member class. The Gym class will have a container of Member object called members. So if I'm using Pytho...Read more

object oriented - Is it good practice to create a static class for database tables calculations?

I need to implement some system (using python pandas dataframe in my case) that parses raw data, then adds on calculated data, and then validates that calculated data (boolean output on some columns)I couldn't make this problem simpler than what is below, so please bear with me.Assumption: this is and always will be single threadedThe flow I think of implementing:Read raw data into a dbQuery the db, to obtain result (some other table)Parse the result (map or reduce operation, or multiple operations)Put parsed result back into original table, or...Read more

object oriented - Initiating a class from its static method

What is the stand on initiating the class from its own static method? Are there any good practices about this? I feel need of initiating a class from its static method while implementing a job scheduler as a backend of a GUI application. I can always make a util method instead of static method but realized i do not have a strong opinion on this. What principles i should follow on this?...Read more

object oriented - Why shouldn't I create a class for every property?

In a particular program I had written, I noticed I had a few classes with this pattern:class IdObject: '''Objects with generated id properties''' def __init__(self, id_generator): self.id_generator = id_generator self.id = id_generator()class Node(IdObject): '''Represents a node in the graph''' def __init__(self, id_generator): super().__init__(id_generator)That is, there was particular property that I wanted a class to have, so I made a class that instantiated that property, and then just subclassed from that o...Read more

object oriented - What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my parse() method is defined inside a parser.py file. If I'm not structuring the project in terms of classes and objects and states and attributes, then what paradigm is this? None?...Read more

object oriented - use always get and set methods is a bad practique, is call directly an attribute class a bad practique in OOP?

I have a doubt about if there are some recommendations for call directly an attribute in a classI think that in OOP you always should call an attribute by the get method.For example:On setpublic setAtribute(Atribute atr){ this.atr = atr;}On get public Atribute getAtribute(){ return this.atr;}On the constructorpublic Constructor(Attribue atr){ setAttribute(atr);}If the attribute is injected in the super class I use this way to call it, on inherits class:@Injectprotected Attribute atr;public Attribute getAttribute(Attribute atr){ return atr...Read more

php - Using the objects retrieved at the time of request validation

I hope the question title already answers the subject here. Lets say I have a number of ids that needs to be validated in a request.Example:request uri: [POST] /album/{album_id}/songRequest payload:[ "song_title": "hello world", "genre_id": 2, "artist_id": [100, 102], "lyrics_by_id": 201]Now, as we know we would definitely have to validate those ids, for which we run some queries over there.Is there a way out, where we can use those objects or data retrieved from database in order to use it in the rest of the code?...Read more

c - Reading problem of object-oriented concept about the book "Object-oriented software construction 2/e"

I've been learning object-oriented concept from this book, and stuck in a specified concept in the middle of chapter 6.Because with no brief explaining beforehand, no one could understand my question; so I'm giving it first.The purpose of chapter 6 is teaching how to describe objects by using abstract data descriptions; three criteria are given.The descriptions should be precise and unambiguousThey should be complete — or at least as complete as we want them in each case(we may decide to leave some details out)They should not be overspecifying....Read more

object oriented - Is 'Keep it looks similar to sample code' a valid reason to prefer WET over DRY principle?

For example, for oauth, I may need to copy and paste oauth and oauth callback code like it (assume Client is the framework I use, I don't use real framework like google because I want to simplify the code):sample code:public function oauth(){ $client=new Client([MY_APP_ID,MY_APP_SECRET]); $client->setCallbackUrl(SOME_URL); //some $client settings header('Location: ' . filter_var($client->getURL(), FILTER_SANITIZE_URL));}public function oauth_callback(){ $client=new Client([MY_APP_ID,MY_APP_SECRET]); $client->setCallbackUrl(SOME_U...Read more