abstraction

Functional programming and dependency inversion: how to abstract storage?

社会主义新天地 提交于 2019-12-08 18:33:42
问题 I'm trying to create a solution that has a lower-level library that will know that it needs to save and load data when certain commands are called, but the implementation of the save and load functions will be provided in a platform-specific project which references the lower-level library. I have some models, such as: type User = { UserID: UserID Situations: SituationID list } type Situation = { SituationID: SituationID } And what I want to do is be able to define and call functions such as:

What is the modern OpenGL equivalent to glBegin/glEnd

巧了我就是萌 提交于 2019-12-07 17:29:46
问题 I'm building a graphics API for OpenGL, which is based off the basic call-to-draw graphics style. Basically, instead of storing the data into the GPU, and call it using it's handle, give the info to draw what it should be drawing each update. I know it's slow, but it's simple and it's for non-performance critical applications. Anyway, is there any modern equivalent to glBegin/glEnd? It doesn't have to a call for every vertex, but a way where I can send the data each update, without storing

Is having a wrapper for your IoC a good idea?

瘦欲@ 提交于 2019-12-07 13:36:44
问题 I have been using StructureMap for more than a year now. And all this time I used to have a wrapper class called IoC which looked like this class IoC { public static T GetInstance<T>() { return (T)GetInstance(typeof(T)); } public static IEnumerable<T> GetAllInstances<T>() { return ObjectFactory.GetAllInstances<T>(); } public static IEnumerable GetAllInstances(Type type) { return ObjectFactory.GetAllInstances(type); } public static object GetInstance(Type type) { return ObjectFactory

C++ zero-cost abstraction for SoA/AoS memory layouts

徘徊边缘 提交于 2019-12-07 06:30:36
问题 Say I have a large code using Array of Structures (AoS) memory layout. I would like to build a zero-cost abstraction in C++ which allows me to switch between AoS and SoA with as little refactoring effort as possible. For instance take a class with access member functions struct Item{ auto& myDouble(){ return mDouble; } auto& myChar(){ return mChar; } auto& myString(){ return mString; } private: double mDouble; char mChar; std::string mString; }; which is used inside a container in a loop std:

Proper way to abstract Realm in Android apps

扶醉桌前 提交于 2019-12-07 04:45:11
问题 I'm trying out Realm.io in an Android app, though, to stay on the safe side, I would like to abstract the DB layer so that, in case of need, I can switch back to a standard SQLite based DB without rewriting most of the app. I'm however finding it difficult to properly abstract Realm due to it's particular nature: When tied to a realm, RealmObjects are proxies so I cannot pass them around as they were POJOs. All Realm instances need to be properly opened and closed for every thread they are

Cakephp: Abstracting AppController another level, possible?

末鹿安然 提交于 2019-12-07 02:39:45
问题 I was wondering if it's somehow possible to add another abstraction controller between AppController and my app's other controllers? So that my controllers, e.g. UsersController extends SecureController and SecureController extends AppController. Also I want to be able to have other controllers extend AppController directly: SomeNonSecureController extends AppController. this is because my current AppController has all sorts of Auth and ACL stuff in its beforeFilter, but i also have

Design of interface abstraction

亡梦爱人 提交于 2019-12-07 01:27:24
问题 Currently, I try to write a small game program (Skat) as a hobby project. Skat is a trick-taking game were two players play against a single player. As there are different kinds of players (lokal player, network player, computer, etc.), I wanted to abstract the interface to the player. My basic idea is to use a typeclass Player , that defines all kind of things, a player have to do and to know (playing a card, get notified about who won the trick, etc). Then, the whole game is just done by a

How to let a function [a] -> [a] operate on [(a,Int)]?

牧云@^-^@ 提交于 2019-12-06 19:44:11
问题 I find myself often writing code following the pattern: foo xs = map snd $ filter ((< 10).fst) $ zip xs [0..] bar ys = map snd $ sortBy (compare `on` fst) $ zip ys [0..] Now I want to abstract this away foo = indexesOf (filter (<10)) bar = indexesOf sort indexesOf :: ([a] -> [a]) -> [a] -> [Int] indexesOf f xs = map snd $ magick $ zip xs [0..] where magick = undefined How to perform the magick ? 回答1: Your type signature won't work. You need to be able to give the passed function a list of

Enum abstraction problem

空扰寡人 提交于 2019-12-06 13:32:28
问题 I am currently struggling with a java abstraction problem. I have something like this: public interface State { }; public interface Dynamics { getObservationChance(State state, Observation observation); }; class SpecialState implements State { }; enum SpecialObservation() { FREE, WALL, etc. } class SpecialDynamics implements Dynamics { getObservationChance(State state, Observation observation) { // state should be SpecialState, observation should be SpecialObservation! } }; class Main { Main

Mysqli abstraction, fetching arrays from prepared statements

风流意气都作罢 提交于 2019-12-06 11:58:03
问题 Lately I've stumbled upon an error in a lib that used to work just fine, and I'll be damned if I can figure out where it is. The code sample is below, and I apologize for the debug stuff that's inside it, but I'm trying to get it to work. The problem is that $temp is an array with correct key (the name of the columns) but all the values are NULL. I think the problem lies in the call_user_func_array(array($query, 'bind_result'), $params); bit, but can't really wrap my head around it. public