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

1
vote
0answers
11 views

Add item to an Array 2D using LINQ

I've wrote a generic function to add an item to an Array 2D This is what I have: Private Sub Add_Item_Array_2D(ByRef Array_2D As String(,), _ ByVal Items As String()) ...
1
vote
2answers
70 views

Covariance in generic collections

I have a some classes and interface public interface IGeoObject { GeoCoordinate GetGeocoordinate(); } public class User : IGeoObject { public GeoCoordinate ...
1
vote
1answer
48 views

Opening a list of URLs and splitting the queries into different files

I recently made a program in Python to open a list of URLs and split the queries into different files. I want to make this code more generic and simple. I am open to suggestions. def parse_file(): ...
3
votes
1answer
36 views

How can I improve my Java MethodPointer?

This was just an experiment to see if I could replicate something like C++ function pointers in Java. Basically, the idea was to have an object which represented a method call, and when you call ...
2
votes
1answer
100 views

Using generic methods for basic crud operations

Regarding re-usability, is this OK? What might go wrong? What would be a better design? Performance-related issues and any other comments are welcome. package sample.library.dao.util; import ...
0
votes
0answers
66 views

Binding and iterating a database table to a List<T> in C#

I would like to iterate through the records of a database table using a C# List of my custom class. Is this the most performant way to handle this? (Simplified for readability) static void ...
3
votes
1answer
39 views

Refactoring my windowsFormApp code

I have around 150 lines of code that I managed to optimize. But, because my two methods and the six if-statements almost are identical, could there be room for improvement? Maybe it could be done ...
2
votes
1answer
96 views

How to remove duplicated code? AOP and Generics are Ok

I have figures - TriangleItem and CircleItem: public abstract class BaseItem { protected int _id; protected string _description; } public sealed class TriangleItem : BaseItem { public int ...
2
votes
3answers
146 views

Better way to write generic method to convert List<List<T>> to T[][]

I was working through getting myself past the creation of a generic method, that converts a List<T> or List<List<T>>, to T[] or T[][] respectively. Well, let's just consider a ...
2
votes
0answers
254 views

Review my Generic ASP.net MVC controller that generates many pages?

I recently set out to create an open-source ASP.net MVC web development framework. Specifically, I wanted to automate some of the tasks associated with the creation of data-driven applications. I've ...
0
votes
0answers
120 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
75 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
221 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
237 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
258 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
289 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
177 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
83 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
160 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
678 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
90 views

Improving my code (make more generic)

namespace SFE.Workflow.Commands { public class SendEmailToAMCommand : ActionCommand { private readonly Func<IApplicationRepository> applicationRepository; private ...
3
votes
2answers
90 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
207 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
121 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
117 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
126 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
376 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
328 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
1k 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
189 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
451 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
218 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
141 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
2k 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
187 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
61 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
839 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
381 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
179 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 ...