|
Pete O'Hanlon wrote: as I and others will be voting to remove this message
Awww damn, looks like I was too late to vote on it
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Welcome back Paul - I haven't seen you around for a while.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks, man. Have been busy and now found some time to come around here again
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
You present yourself and your company as "too damn cheap to buy an ad". This kind of PR is bad branding and damaging to the image of your company
Could they afford one?
|
|
|
|
|
Does the following C# code belong to a design pattern? If so, which one?
public class Fee
{
private Bar<Baz>.Getter myBaz = Bar<Baz>.GetAGetter();
public void Fi()
{
myBaz().DoStuff();
}
public void Fo()
{
myBaz().DoStuff();
}
}
public class Bar<T>
where T : new()
{
public delegate T Getter();
public static Getter GetAGetter()
{
T requestedItem = default(T);
return () =>
{
if (requestedItem == null)
{
requestedItem = new T();
}
return requestedItem;
};
}
}
public class Baz
{
public Baz()
{
}
public void DoStuff()
{
}
}
Bar returns a closure with an upvalue of type T. In this example, Fee's myBaz method will always return the same Baz object, and it won't be instantiated until the call to myBaz().DoStuff() during either the Fee.Fi() or Fee.Fo() method, whichever is called first.
So basically Bar provides lazy initialization of a Baz (in this case) to Fee (and presumably other classes). Do we have a name for this?
If this question has already been asked in this forum, please point me to the message.
|
|
|
|
|
At a quick glance, seems like a Singleton but a Generic Singleton Pattern. May I ask why it is important to know whether the pattern exists or not? Patterns come with time when they have proven to be successful solutions. What unique problem does your pattern above solve or why do you need such a pattern? Is it making things easier or harder?
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
I'm mostly curious. I'm wondering if such a pattern, or something similar (or better or more fully thought out) has emerged already in the community.
I know this code doesn't match a GOF pattern, and that it looks like a not-very-good singleton. You might call it a singleton for the calling scope of Bar.GetAGetter(). There's nothing to prevent two scopes from getting separate values though. Indeed, a single scope can get two separate values simply by calling Bar.GetAGetter() twice - each call returns a method that returns a distinct value. This is by design - it's not supposed to be a singleton.
Like I said, I think the value of Bar is that it encapsulates lazy instanciation. Since lazy instanciation is very common, and it takes 3-5 lines of code every time, and this replaces it with 1 line of code, encapsulating it seems like a good idea for all the usual code reuse reasons.
|
|
|
|
|
I'm looking for some feedback on the best/alternate ways to handle the following scenario:
Widget (defines the pool from which to create widgets)
========
Id
UserControlPath
DefaultWidget (provides a set of default properties for a widget instance)
==========
Id
WidgetId
Name
UserWidget (defines a widget with properties customized by the user)
===========
Id
WidgetId
DefaultWidgetId
Name
Given the 3 database tables above, how would you create a DTO object? I could have a class per table, but then I have to do additional queries or work with additional objects for all the data I need. I could use nested object (UserWidget has Widget.UserControlPath property). I could flatten out the UserWidget to have those properties plus a UserControlPath property.
When loading a UserWidget, I cannot display it without the UserControlPath value.
When saving updates to the properties of a UserWidget, the UserControlPath is read only - but WCF data contracts do not support the idea of read-only properties(As far as I know). Saving full object graphs can quickly become complex.
How do you model similar relationships?
Thx.
|
|
|
|
|
Leftyfarrell wrote:
I could have a class per table
I think this is a bad idea. Your tables are designed so data is normalized. Your code--classes--should be designed to normalize behavior not data. Think of your problem domain, jot down all things you need to do to these objects, assign these things to appropriate classes. Try to normalize behavior by using inheritance.
That is all I can say because I don't know too much about what you are trying to do.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Thanks for your reply.
I agree that I don't like the class per table idea. Tables are normalized. Classes should represent proper domain objects.
The question then becomes, where do you draw the line on CRUD operations. To me, a UserWidget without the UserControlPath property is kind of useless. On the other hand, when you save a new UserWidget, you cannot edit/change the UserControlPath property value. You could consider it a lookup and allow them to change the WidgetId (indirectly choosing a different UserControlPath).
But, if the UserWidget is exposed via WCF, read-only properties are not supported. So I can expose the WidgetId, which is editable, but if I provide a string UserControlPath property, it becomes editable on a WCF data contract, which I don't want.
So they load up a UserWidget object, change the UserControlPath string value, and submit the object for saving... now what? Ignore the property value? Allow the saving of this instance to change the value for all other instances? Neither sounds very elegant.
|
|
|
|
|
Do something like the following the following--private setter:
[DataMember()]
partial public class Foo
{
public string FooBar
{
get {;}
}
{
private set { ; }
}
}
Leftyfarrell wrote:
The question then becomes, where do you draw the line on CRUD operations.
What do you mean draw the line?
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Thx, will check into that.
By draw the line, I mean with nested objects in an object graph. Not really shown in my object/table example above. But for instance say you have a Course, Session, and Location. A course has multiple sessions, and each session has a location.
Does your Course object have a Collection<session> objects for reading convenience? What about CRUD on the Course, where do you "draw the line"... if you add a Session to the collection, do you now save the Course AND insert a new Session? If the Session has a Location within it, and you add a new Location to a new Session and add that to a Course and save the course, do you Insert the Session and the Location?
It seems to me that dealing with object graphs for CRUD operations can get complex quickly. But having those properties does properly represent the domain model, and certainly does improve the way you work with the data when only reading it (loading Course, Session and Location info for display purposes). Then for performance reasons, you might get into lazy loading, although that may not be feasible either across WCF boundaries.
It seems all about the trade-offs and I'm just looking for the right balance that makes sense.
|
|
|
|
|
Okay I know what you mean.
It all depends on the requirements. For example, let's say you are managing customers, their orders, and lineitems. Now the questions to ask are:
1. Within my problem domain, do I want to create LineItems or do I only select from LineItems and add to order? If you only select then LineItem will not have any CRUD operations except Retrieval.
2. What about Customers? Will I be adding new customers who have absolutely no orders into the system? Chances are yes, therefore, therefore their might be times you want to load a customer to edit their information. It does not make sense when you call Retrieve (R from CRUD) on customer to also load their orders, and all the line items for the order if all you need to do is change the customer's name from Bob to Rob. But if within your domain you never do any CRUD operations except Retrieve on customers (customers are added using some other app), and the only time you retrieve them is to load their orders then it make sense to retrieve all orders and lineitems when a customer is loaded.
Where to draw the line? You choose by looking at the problem at hand.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
That is a good analysis of some sample requirements. The next complexity that comes to mind is definition of the entities to support both scenarios.
Admin area allows you create a customer. User area allows viewing the Customer, together with Orders and LineItems. I assume the same Customer entity is used for both areas of the system.
Now in the admin area when creating a customer, you simply have a Collection<order> that is null. This keeps things fairly simple. If it was not null, would you design your system to handle it (insert Orders too) or would you throw an exception and force things to remain simple for CRUD operations beyond reads?
|
|
|
|
|
A Customer should have a collection of Orders, and Orders should have a collection of LineItems. As soon as you create a customer, you know you need orders, therefore, instantiate a collection of orders. Do not leave it null but leave it empty and then orders can be added. If orders are not allowed to be added then throw exception or handle it some other way.
Leftyfarrell wrote:
you simply have a Collection that is null.
Like I said above this should be empty but not null--at least this is how I will design it. When a customer enters a store, he/she grabs a shopping cart but it is empty and then if he/she needs something she adds it. If he/she does not grab a shopping cart then what? Someone else has to grab it--I don't know about this.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Hi,
I wrote myself an Access db several years ago to do some things for my checkbook and budgeting and I've really enjoyed it ever since. Lately I've been thinking about writing it as a stand alone program so I could let my family and friends use too (I don't want it to be Access dependent because I don't want to have to troubleshoot and support it on different versions of Access or MDAC).
Anyway, I once took a class on OOP Logic and a C++ class, and as I was thinking of how to design it, I was thinking in terms of objects. For instance, a transaction would be an object with attributes like a date, amount, etc. But then I realized that designing it this way seems to be fundamentally different from the way I did it originally with Access. So it looks like the first big decision I have to make is to decide whether to use object oriented db design or relational db design. Is this true, and if yes, which way would be better to go for a checkbook/budgeting app?
Thanks for your help.
|
|
|
|
|
Here's some thoughts of the top of my head.
copec wrote: whether to use object oriented db design or relational db design
It's not an either/or decision. If you think of the app as having two parts (i.e a user front end and a data storage back end), the front end could be OOP and the back end a relational db.
The two ends have to communicate and you can do that in a number of ways, two possible approaches are:
1. Use the data binding common in MS Windows forms and IDEs such as Visual Studio. This is essentially what Access does when you build forms using the wizards.
2. Put a data access layer (DAL) between the front and back ends. Possibly Model-View-Controller pattern. Enterprise solutions ought to go down this path, but it might be overkill for a single user app.
If you don't want to use Access you have to decide how to store the data. Options include: flat files (CSV?), XML, some other database.
You need to determine what the other users have on their machines before deciding.
"Thoughts of a dry brain in a dry season" - Gerontion, T S Eliot.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks David.
Wow, you used a lot of words a phrases there I've never heard before.
It's good news (I think) that I can use my OO knowledge with standard RDB tables to store the data because I already have a working model in Access and I understand a little about OOP. How do I decide what language, db, gui, toolbox, etc to use keeping in mind: 1) I have a little c++ training, 2) need the most stability I can reasonably get, 3) free tools that I can sell if I decide to one day? btw, Windows only compatibility is fine, especially as I'm assuming cross-compatibility requirements would only make finding a solution more difficult.
Thanks again.
modified on Saturday, July 11, 2009 10:34 PM
|
|
|
|
|
Here are some thoughts. (Rather longer than I anticipated!)
If you have a developer edition of Office you can package your .mdb together with a run time version of the
Access engine. This would be the simplest thing to do - I believe it would take care of the MDAC issues but have never used it.
IIRC the license is that you must have the developer edition Office Pro is not valid.
The beauty of Access is that the .mdb file contains everything - user interface (GUI) and data store (i.e. db tables etc).
So the whole app can be self-contained (unless you use linked tables).
If you move from Access then the GUI and and the data store will be separate components that need to talk to each other.
So you have to decide what to use for the data store and what to use for the GUI.
Looking at the data store, main driver for this decision has to be 'What do potential users have on their machines?'
If they have Access why not stick with it? If they don't then some possible options are.
1. Use flat/text files - the traditional (antedeluvian?) way that requires a lot of coding
(having said that, I know of one major UK retailer whose warehouse management system is run using flat files.)
This approach would mean that the users would require nothing special.
However, you would have to think about securing the files so users cannot edit or delete them.
2. Use XML - this is what many would advocate. Essentially they are structured text files on steriods. But that requires learning about XML.
Similar pros and cons to flat file. But there are other benefits and lots of example code on the web.
3. Use an OOP language and the object serialization that is built in.
Not always as easy as it seems but would be self-contained.
4. Use a relational db.
There are some free ones that you could investigate e.g. SQLite, MS SQL Express.
You would need to be able to package and distribute the db with your GUI app, and that might bring problems similar to the MDAC ones with Access.
For the GUI and the ability to communicate with the data store you still have to ask 'What have the users got on their machines?'.
You also have to ask 'What am I comfortable with and how quickly can I get uo to speed?'
These days you're pretty much obliged to use an OOP language. Possible options are:
1. Java - I once heard it described as 'C++ For Dummies' so knowledge of C++ would be helpful.
It's free and cross-platform and there's some nice free IDEs (NetBeans and Eclipse are considered good).
Personally I think it started off being really good but has now added a plethora of classes that make it just too much of a hassle to do simple things.
Users will need the Java Runtime Engine - but that's free (and there's probably a version on their machines - but might need updating).
2. VB.Net - there's a free version (VB 2008 Express) that comes with the Visual Studio IDE (well a cut down version).
It's a 'true' OOP (unlike VB6 which it is related to it as Italian is to Latin).
It's easy to build apps similar to Access ones (especially if you use SQL Server Express as data store).
Requires .Net Framework 3.5. But that's freely available and re-distributable.
3. C# - similar to Java/C++ in syntax. Also a free Express version.
Same pros and cons as VB, more or less.
4. C++ - there's also a free Express version.
Never used it so cannot comment. I expect it's similar to VB/C# in what it provides.
You could also look at Mono - it's an open source implementation of .Net and available for Linux and Wondows.
Never used it but heard good things about it. Tends to lag behind MS .Net since it's always playing catch-up.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks so much for this info. A lot of it is new but some of it fits in and clarifies other things that were foggy.
It may show that I don't really understand what I'm talking about, but, in no particular order:
--I used to support some Access apps that ran on MDAC and Access on various clients and there were always problems coming up. That's why I'm drawn to developing a truly independent program.
--I'm definitely leaning toward an RDB data store instead of an OODB, or the other choices, because I already have a working -though improvable- model of the data in RDB (my existing mdb) and it seems like the "best" way to store number data.
--From this and other info I've read I guess it's a two way tie between C++ (I had the Intro to C++ class) and Python (seems to be widely liked) for the front-end (is this right terminology?) with Java still kind of in the running (don't love that it is dependent on JVM).
--Should I not be concerned about stability or security of using something built on a platform, like JVM or .net?
--Could you talk more about this?: "You would need to be able to package and distribute the db with your GUI app, and that might bring problems similar to the MDAC ones with Access."
--I understand what the language and libraries are, but could you explain why I need toolboxes, wrappers (like wxpython)?
--Regarding IDEs, I found these at http://wiki.python.org/moin/IntegratedDevelopmentEnvironments[^]. How do I choose between "IDEs with introspection-based code completion and integrated debugger" and "IDEs with integrated gui builder"?
And thank you again. I really appreciate your help.
|
|
|
|
|
copec wrote: developing a truly independent program
Not sure you can develop a completely independent program. If you create an executable (i.e. .exe) it will almost certainly depend on some system .dlls - pretty much unavoidable. It will also depend on having an RDBMS (e.g. SQL Server) if you use a relational db.
copec wrote: don't love that it is dependent on JVM
You don't need the JVM on user's machines, just the JRE - at least that's my understanding. If you use C++ to create a .Net app, user's would need the .Net framework installed. I don't know Python so don't know its dependencies.
copec wrote: Should I not be concerned about stability or security of using something built on a platform, like JVM or .net?
These are probably concerns irrespective of platform. How critical they are depends on the nature of the app.
copec wrote: Could you talk more about this?: "You would need to be able to package and distribute the db with your GUI app, and that might bring problems similar to the MDAC ones with Access."
Once the app is created you have to have some means of distributing it. If it comprises a .exe plus supporting .dlls and a rdb back end you have to get them onto the user's machine. With 'traditional' .exes there are issues with differing versions of .dlls (commonly referred to as dlHell, similar to MDAC issues. These have pretty much gone away in .Net - there's no problems with having multiple versions of the same .dll.)
copec wrote: explain why I need toolboxes, wrappers (like wxpython)?
Strictly you don't, if you are prepared to create your own widgets such as buttons, textboxes and comboboxes to populate forms (you would have to create a widget for the form as well). If you take C++ as an example, the language itself does not provide any GUI widgets at all. So to create a GUI you need a toolbox of widgets that you can hook up to. MS Visual Studio provides such a toolbox that's available to any of the languages it supports (true even before .Net e.g. VB6 and VC++). I don't know what the wxpython wrapper does (quick Google says it's a wrapper around a widget toolkit).
So it looks like if you use Python you have to make sure the wxpython wrapper plus the toolkit plus Python runtime (I think it uses a VM like Java since it compiles source to bytecode) is installed on user machine.
copec wrote: How do I choose between "IDEs with introspection-based code completion and integrated debugger" and "IDEs with integrated gui builder"?
Ideally you want an IDE that has auto completion (Intellisense in MS speak), an integrated debugger and a gui builder. This is what VS provides. Which you choose depends on how confident you are with the language. Auto completion is useful (reduces silly typos). An integrated debugger will allow you to step through code line by line to find errors. A GUI builder is almost essential but you could write all the code you need in Notepad - I've done this for simple C# apps but it's a pain. It's just so much easier to drag and drop controls onto a form in the designer than to craft code to place them exactly where you want them to be.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks again, David.
I get your point about dllhell compared with Java or .net, but can't that be avoided also by using unregistered dlls? (I read that somewhere and I don't know the ramifications, I'm just throwing it out there to see what you think).
riced wrote: So it looks like if you use Python you have to make sure the wxpython wrapper plus the toolkit plus Python runtime is installed on user machine.
Would or could this normally be done during the install of the program itself on the client machine?
If I used an IDE other than VS, like say if I used an IDE for Python, like NetBeans for instance. Would I need to gather my "widget toolkits" and plug them into the IDE somehow, or how do you use them from within the IDE? Or does my question show that I don't quite understand?
Thanks.
|
|
|
|
|
You can avoid dllHell by using unregistered dlls, my point was that however you create the app there will still be a need to package its components to get them onto user machines. If the app relies on particular system components (e.g. .Net 3.5 framework, JRE or wxPython) you also need to either get them onto to the machines or abort the installation.
As I said I don't know Python so cannot be specific about what is required. However, I understand Python can be used with a wide variety of toolkits and that there's a large number of IDEs that allow you to develop GUI apps.
I would expect that if you download Python it will give the option of installing a toolkit. If it does not, there's likely to be some info on how to install a toolkit. Once that's done I would expect the IDE to either pick up the toolkit or allow you to hook into it.
You might find that the IDE expects to find a particular toolkit installed (a quick google indicates that wxPython is the toolkit most likely to be supported). Sun was doing something to support Python in NetBeans (as of Nov 2008) but I don't know how far it's got.
BTW if you use NetBeans you need to have Java installed - at least you did when I last used it (about 5 years ago).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks for the info, David.
I hadn't considered the issue of installation until now, but I see what you mean about how the user would need all necessary components to be able to run the program. At what point during development would I need to start thinking about, and planning, and taking actions for, the installation process of getting all necessary components onto an end user's machine?
|
|
|
|
|
Probably from the start.
If you have a target set of users in mind it is worth finding out what they are likely to have installed. For example if they have .Net 2.0 it would make sense to consider build the app using that framework. There may be good reasons not to do so but then you have to look at having some installation package and the licensing conditions regarding redistribution of the components such as the run time engine (e.g. JRE if you do it in Java).
If you wait until the app is in development you might find that it's difficult or impossible to actually distribute it.
Ideally, you should set up (at least) two machines: one for development and one for production (i.e. to mimic users' machines). You could then install the proposed development platform, build a 'Hello World' app and try to package and install it on the production machine. This would also allow you to test various distribution channels e.g. from CD or via a download from a network.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|