code-reuse

What is a good strategy for separating layers for an application that can be used online and offline?

孤者浪人 提交于 2019-12-06 05:05:43
问题 I have a Java web application that has a 'disconnected' Java Swing desktop app. Using the desktop app users connect to the internet and download data they need from a server. They can disconnect and use the application offline. When they reconnect to the internet they can sync their data back to the server. The server itself is a Java EE web application and the desktop app is a limited functionality version of the web app. Up until now all business logic and data access code was coded

What to include in a Utility Library [closed]

爷,独闯天下 提交于 2019-12-06 04:36:28
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 3 months ago . With more and more projects under my belt I find that I am often repeating many common tasks from project to project, client to client. So I have started to assemble a "utility" library, a collection of these common elements that are often repeated from project to project. So far I have utilities to resize images, export data grids to excel, send e-mails, and replace

Best ways to reuse Java methods

送分小仙女□ 提交于 2019-12-06 01:17:02
问题 I'm learning Java and OOP, and have been doing the problems at Project Euler for practice (awesome site btw). I find myself doing many of the same things over and over, like: checking if an integer is prime/generating primes generating the Fibonacci series checking if a number is a palindrome What is the best way to store and call these methods? Should I write a utility class and then import it? If so, do I import a .class file or the .java source? I'm working from a plain text editor and the

Best way to populate SelectList for ViewModel on GET/POST

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 00:41:27
I have the following ViewModel: public class EditViewModel { public int FooType { get; set; } public IEnumerable<SelectListItem> FooTypes { get; set; } } I originally populated it in my Edit action like so: public ActionResult Edit(int id) { EditViewModel model = new EditViewModel(); model.FooTypes = new SelectList(repository.GetFooTypes(), "Id", "Value"); return View(model); } When I created the action to POST the values I had to repeat the same code: public ActionResult Edit(int id, EditViewModel model) { if( !ModelState.IsValid ) { model.FooTypes = new SelectList(repository.GetFooTypes(),

Where shall I put my utilities classes in a ASP.NET MVC3 application?

谁说我不能喝 提交于 2019-12-05 22:32:04
问题 I am developing a web application in ASP.NET MVC3 with C# and Razor. I need to create an utility class where I put functions to convert string into dates(years, months, days, etc...). In ASP.NET Web Forms I used to place this kind of classes inside the App_Code folder. In MVC there is not such folder and I don't think utility classes belong neither to Models nor to Helpers (a folder I created to put my extensions on HTML Helpers). I read that is a good practice to place the utility classes in

How to re-use forms with some fields left out in Symfony2

梦想与她 提交于 2019-12-05 17:38:29
I am using embedded forms to be able to make a registration form, which holds fields of several related entities. As explained to me in my question over here: Symfony2 form where the data objects doesn't match exactly what needs to be filled in This works just fine. But say I want to re-use one of the forms that I embedded, but leave some of the fields out. Then what are my options? Do I create an extra formType which extends the original one? Do I decide in the view to leave some fields out? This doesn't feel like a view decision in my opinion though. And extending for each different use case

Can I share code between different parts of Chrome Extension?

为君一笑 提交于 2019-12-05 14:50:08
问题 Let's say, I have a function: var rand = function(n) { return Math.floor(Math.random() * n); } Can I use this function in both Content Script and Background Script without copypaste? Thank you. 回答1: Yes. You could have an external JS file which is loaded as part of the background and the content script (like any normal JS file). Just add it to the background and content script file arrays in the manifest and it will be loaded for you. For example if our shared function reside in

How to store reusable code in Visual Studio 2010?

拥有回忆 提交于 2019-12-05 14:14:30
Is there any way I could save my block of code in Visual Studio 2010 and reuse it in my future web applications without having to " Add existing files" ? Is there a feature in VS2010 that lets you globally store these blocks of code? Thanks! Oded pretty much covered it but I'll just reiterate here. There are three main ways you can do this depending on how much code you want to store. For a little code just copy the code to your Toolbox: http://blogs.msdn.com/b/zainnab/archive/2010/01/24/drag-and-drop-code-onto-the-toolbox-vstiptool0007.aspx For a little code to very large blocks of code (with

React Native: How to split a file up into multiple files and import them?

纵饮孤独 提交于 2019-12-05 12:26:10
问题 I am writing my first app in react native and my js file is getting pretty big. What is the proper way to split the file up. If i have something like var MyClass = React.createClass({ ... }) Can I save it at myclass.js and include in by some command in another js file? 回答1: In general you can do the following: var MyClass = React.createClass({ ... )} module.exports = MyClass; This way you tell what should be publicly available. And then, in your former big file you can load the contents like

Use Ada code in Android

半城伤御伤魂 提交于 2019-12-05 06:17:29
Is there any possibility to use old Ada code in Android? I have an old script written in Ada and it would be great if I could just use that code in Android directly (via NDK or JNI etc). Is this possible? Or should I rather port the code? Here are some links I found but I don't really understand in what extend they answer my question: http://en.wikibooks.org/wiki/Ada_Programming/Platform/VM/Java http://code.google.com/p/javada/ http://code.google.com/p/jgnat/ http://en.wikipedia.org/wiki/GNAT Added: http://groups.google.com/group/comp.lang.ada/browse_thread/thread/4cb1f8d1c17d39a8?pli=1 I