Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

learn more… | top users | synonyms

0
votes
0answers
50 views

Tips on multiple key Map-wrapper

I'm creating a simple generic Map-wrapper with multiple keyed values. I'm intending to use it with storing edges in a graph, where an edge goes from one vertex to another. Thus, I can fetch any of ...
2
votes
2answers
72 views

Generically typed interface

I came across the following code in our code base: public interface ICloneable<T> { T Clone(); } public class MyObject : ICloneable<MyObject> { public Stuff SomeStuff { get; set; ...
1
vote
0answers
148 views

Generic Task Blocking Queue

A generic blocking queue has the following properties: It is thread-safe. It allows queuing and de-queuing of items of a certain type (T). If a de-queue operation is performed and the ...
1
vote
1answer
139 views

Java; Generic Observer/Observable - is this as messy as I think?

I have recently had a whole load of help trying to roll my own loosely-coupled Observable/Observer paradigm, here: Loosely coupled observer pattern To keep things simple and to aid in my ...
6
votes
2answers
148 views

Improvement requested for: Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: public T ...
2
votes
2answers
177 views

Sequential Execution: Orchestrator Pattern

I built a code piece that makes it easy to execute a set of sequential operations, that might depend on the same parameter value (passed across the execution) or might need a particular parameter. ...
6
votes
2answers
141 views

Generic wrapper for equality and hash implementation: Is there a way I can make it more efficient?

I was writing an answer in another thread and came across this challenge. I'm trying to have a generic class so that I can delegate the routine (and tiring) Equals and GetHashCode implementation to it ...
0
votes
2answers
79 views

I would just like to find out if the code below is the correct way of creating a generic list and populating it?

using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Text; public class InnerJoinTables { public ...
4
votes
2answers
129 views

Move object by one up or down algorithm in a custom order

Basically, I did an object (using hibernate) with a field called sorting_order. This field needs to be unique and I wish to swap two object by one. So one element has to be after or before the current ...
3
votes
2answers
254 views

Is there a better way of defining generic entity classes?

I have some entities in use in my project, and to make things easier, I would like to have the type of the key for that entity defined via a generic. E.g.: public abstract class Entity<T> { ...
0
votes
1answer
85 views

Improving my code (make more generic)

namespace SFE.Workflow.Commands { public class SendEmailToAMCommand : ActionCommand { private readonly Func<IApplicationRepository> applicationRepository; private ...
3
votes
2answers
79 views

How would you improve this object model design to get around Covariance Issues with ObjectModel.Collection<T>?

Consider the following simple relationship. Code [DataContract(Name = "Wheel")] public class Wheel { } [DataContract(Name = "OffRoadWheel")] public class OffRoadWheel : Wheel { } ...
7
votes
2answers
179 views

Synced/Atomic access

Forward I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below. If this is similar to other implementations, I would love ...
1
vote
3answers
116 views

Can I somehow tidy up this (overuse?) of generics?

I'm building a generic flat file reader which looks something like this. public class GenericReader<TComposite, THeader, TData, TTrailer> where TComposite : GenericComposite<THeader, ...
1
vote
1answer
110 views

Refactoring code into a generic method [closed]

I have a reoccuring code block in my EntityFramework backed repository which I would like to genericise somehow and call as a method, so reuse the code rather than repeat it. The current code block ...
2
votes
2answers
119 views

how to write generic extensions for standard collection types in java?

I am a Java beginner and I am looking for an idiomatic way of writing a function that involves generics. I wrote this helper class (below) that pushes items into a sorted generic collection and I ...
4
votes
2answers
284 views

Generic Wrapper for a Task-based API

I've written a piece of an ugly code. The idea was to provide a clear-looking, type-inferring framework to test a task-based API (it's for integration testing, and test methods should be as clear as ...
7
votes
1answer
293 views

using <T> in generic delegates?

Here is my problem. Do I need to give a new identifier to each delegate I write of the following delegate type? like so: or could i use one delegate that accounts for any Datatype I need to use so i ...
2
votes
1answer
716 views

Review of a generic request handler class (RestSharp)

I wrote a class that uses RestSharp to access Rest and HTTP API web services. I tested it and it works however I was wondering if any changes could be made to it to make it better. public class ...
10
votes
3answers
176 views

Cast inside the method or let the client code cast, which one is better?

I have two choices of implementing a method, the first one is a generic type where the client code does not have to cast public T GetControl<T>(string controlName) where T : Control { ...
3
votes
3answers
324 views

ReadOnlyCollection - my alternative to .NET one

I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection. The goal was: consuming classes should only see what I want to show them, not whole underlying collection. For ...
4
votes
2answers
203 views

Online-Offline Class Manager

Router is a generic class that manage multiple contracts that. It is able to find out wheter it's an online or offline situation, on the very moment when an operation is being made. There's a really ...
4
votes
1answer
140 views

OOP: Need tips of my approach in .Net

I am looking for some different approaches to this following OOP scenario. Dim pb As Object = Nothing If radCars.Checked = True Then Dim productBase As ProductsBase(Of CarColumns) ...
2
votes
1answer
139 views

Generics: Is this improper use?

I have a class library in which I'm using generics as below. I'm not sure if it's an improper use or not. So aside from the fact that it works and everything "depends", id like some specific critique ...
1
vote
1answer
1k views

Polling loop to run in a background thread

I came up with the idea of a small utility class that will poll some delegate until the response received meets some condition, upon which it will notify the main thread which can take the appropriate ...
3
votes
1answer
183 views

Repository Pattern Review

I have following code for a library management system. Is the following code a proper implementation of the Repository Pattern? How can I adapt this code to use generics? Should I let ...
2
votes
1answer
59 views

Generic pass_many(vals, pass_one) to unroll and call pass_one(val)?

I'm trying to create a generic function that takes a data-structure as input and then sends each non-empty item—e.g.: str, int—individually: def print_this(v, delim1="", delim2=""): print v, ...
2
votes
4answers
674 views

Is my Scala Option conversion to Java correct?

Summary: I've implemented what I think is a complete Java implementation of the Scala Option class. Could you please review and let me know if I have correctly and completely implemented it? And if ...
1
vote
1answer
346 views

Java generics, convert nested list to array

I have to interface to some old code using nested arrays, so I have to convert my nested Lists to nested arrays. Any idea, suggestions, improvements are warmly welcomed. public static <E> int ...
3
votes
1answer
174 views

How is the design of this Singleton implementation

I did this as an exercise just to practive/improve using generics. Independent of how useful this implementation of a Singleton is, how is my coding in terms of using generics and any other aspect of ...