1) iPhone development - when to create a class library and when not to? (is there a best practise guide to explain this?)
2) Do you need to take a different approach when you decide to create a class library vs developing a web app or desktop app. Since iPhone app has many views is it better to duplicate functions from one view to another rather than create function libraries for reusable functions? (ie web service functions, should this be duplicated?)
3) Traditionally in a web application, desktop application, when you need to reuse a function more than 2 times, you might consider creating a library, but not all the time it really depends on the situation, is this still true for iPhone development?
A good rule of thumb is to ask yourself: will I use this in another project?
In my opinion, reusing functionality within different views in the same application is not enough of a good case for creating a library.
It's important to notice the differente in reuse between different apps (in which case it's good to create a library) and reuse inside the project (you solve it with good OO design)
You could check this link for a list of open-source iPhone libraries. You'll get an idea on what a library should consist of.
We create a class library when it is useful. Not all classes make sense in a library, and not all libraries need to be created for a particular purpose. General rule (for me) goes something like: If you've had to rip something out of another thing because it was useful, to put it in another thing, odds are good you want to, during the code removal from the first thing, make it reusable.
It may be a good idea, it's again, hard to answer this particular point in the abstract.
That's true for many classes of problem domains, including iPhone development.
Related
I needed to get the root item of a TreeView. The obvious way to get it is to use the getRoot() on the TreeView. Which I use.
I like to experiment, and was wondering if I can get same root, buy climbing up the tree from a leaf item (a TreeItem), using recursively getParent() until the result is NULL.
It is working as well, and, in my custom TreeItem, I added a public method 'getRoot()' to play around with it. Thus finding out this method does already exist in parent TreeItem, but is not exposed.
My question : Why would it not be exposed ? Is is a bad practice regarding OOP / MVC architecture ?
The reason for the design is summed up by kleopatra's comment:
Why would it not be exposed I would pose it the other way round: why should it? It's convenience api at best, easy to implement by clients, not really needed - adding such to a framework/toolkit tends to exploding api/implementation to maintain.
JavaFX is filled with decisions like this on purpose. A lot of the reasoning is based on experience (good and bad) from AWT/Spring. Just some examples:
For specifying execution on the UI thread, there is a runLater API, but no invokeAndWait API like Swing, even though it would be easy for the framework to provide such an API and it has been requested.
Providing an invokeAndWait API means that naive (and experienced :-) developers could use it incorrectly to accidentally deadlock threads.
Lots of classes are final and not extensible.
Sometimes developers want to extend classes, but can't because they are final. This means that they can't over-ride a lot of the built-in tested functionality of the framework and accidentally break it that way. Instead they can usually use aggregation over inheritance to do what they need. The framework forces them to do so in order to protect itself and them.
Color objects are immutable.
Immutable objects in general make stuff easier to maintain.
Native look and feels aren't part of the framework.
You can still create them if you want, and there are 3rd party libraries that do that, but it doesn't need to be in the core framework.
The application programming interface is single threaded not multi-threaded.
Because the developers of the framework realized that multi-threaded UI frameworks are a failed dream.
The philosophy was to code to make the 80% use case easier and the the 20% use case (usually) possible, using additional user or 3rd party code, while making it difficult for the user code to accidentally (or intentionally) break the framework. You just stumbled upon one instance of an application of this philosophy.
There are a whole host of catch-phrases that you could use to describe the reason for this design approach. None of them are OOP or MVC specific. The underlying principles have been around far longer than software engineering, they are just approaches towards work and engineering in general. Here are some links if interested:
You ain't going to need it YAGNI
Minimal viable product MVP
Worse-is-better
Muntzing
Feature creep prevention
Keep it simple stupid KISS
Occam's razor
I've started helping with an open source game (based on Cocoa, Obejctive-C, Xcode). The existing game engine is already setup to allow the character to run around the world, encounter an enemy, and when combat is begun, a characterObject is called with the enemy unit object that is to be attacked. This characterObject has a default method of attacking the enemy.
I wanted to improve on this design by extending the program to allow others to develop a combatUnit plugin that would handle the combat actions in their own programmed way. This could open up the community to develop different styles of combat and come up with their own unique play style.
As I began to look into Plug-Ins and examples on how to build, most of the examples kept the plug-in relatively isolated from the internals of the rest of the program. And any data the plugin required would be passed into the routine(s) themselves.
However, in this case, a combat unit developer might want to have access to numerous external objects in the existing game: a developer might want to also know of any nearby enemy units to avoid any potential adds in a fight and would have to access several of the existing environment objects to get that data, the character might be in a group and the developer might want access to the group info and each players data to determine if they should heal, etc... Not knowing what a developer has in mind, it would be unfeasible for me to attempt to predict and pass in all potential info for them to use.
So, my question is:
Is this a good application for a Plug-In? If so, when developing the plug-in how do I open up the other objects for the plug-in developer to code against?
Is there another approach to solve this problem? Something else than a "Plug-in" that would be more appropriate for the code to have access to the game's objects?
Thanks for you help!
That’s a good case for making plug-ins. As an alternative you could compile the new objects directly into the game or use a scripting language interpreter. But with those you’d have to solve the same problems of how to give access to the internals of the game to the new combat unit.
The cleanest way to do this would be to define an interface to the game (either as a protocol or a base class) and pass that to the plug-in. Using this object the plug-in can then query anything it needs.
In IB one can instantiate controllers, build up references to UI elements, and define action targets. It is also possible to do that programmatically. I wonder what (most) seasoned Cocoa developers prefer?
In many other environments, I would not bother too long with interface builders (lower case), but the Apple tools are clearly a class of their own. Still, do they carry further, or are they beginners' tools? And why?
I think it is clear that they are the right choice for assembling and laying out the UI. But what about associating the UI elements and controller objects?
Experienced Cocoa developers use Interface Builder extensively. It's the inexperienced ones who tend to distrust it, because the UI builders for other environments usually suck, so they assume Interface Builder is like that. It's not. Cocoa and Interface Builder are intimately connected. It's hard to develop an app without using Interface Builder — to the point where if you look through the Cocoa-Dev mailing list archives, you'll see a lot of frustrated developers new to Cocoa asking how they can avoid using IB. The answer both from Apple employees and from veteran Cocoa devs is the same: Just use it.
Think I'm full of crap? Open any professionally done Cocoa app. Seriously — any Apple app, any third-party Cocoa app. Now go to the Resources folder. Poke around and you will see nibs everywhere.
As for how much IB is too much — there is a point where connections will be set up by code. In general, hooking up UI elements and controllers is usually done in IB, and even controller-to-controller connections often are as well, though that's more iffy. It essentially comes down to which is less work to set up and maintain. The big exception to IB's dominance, ironically, is custom views. When you have a custom view that is only used once, it just isn't worth the time to create an IBPlugin for it. In that case, usually the controller is hooked up to the view in IB and then the controller hooks up the view to anything else it needs.
It mostly depends on their background as a developer and what you could consider "experienced".
I've seen people refuse to even open IB.
My opinion is that to make an app that doesn't look like every tutorial app from the iPhone 3G era, you have to use IB, and to eschew it and try to build a good looking sophisticated app completely in code is a waste of time and can make your code hard to read unless its done perfectly.
Like apple's documentation says, the less code you write the less you have to maintain, and I think that it is a very good point.
You associate controllers with UI elements at all times, this is what is called the MVC schema.
Any experienced Mac or iPhone developer will use IB for almost all of their interface wiring, and as an "inversion of control" object creation manager. By putting your wiring in NIB instead of code, it's not loaded until requested, and is easier to manage.
Is OpenSwing a good framework for developing professional desktop application?
I was recently using the OpenSwing Framework. I can say only the best for the functionalities which are provided with the framework. It is a multitier concept with excelent data binding possibilities. My App uses a small Derby DB in background and I’m managing it with hibernate.
I’m sure, you will be able to advance very fast and provide a working prototype very quick. I would advice you to read the available doc first and to run the provided examples (http://oswing.sourceforge.net/).
However, it has another side which you should be aware of and you will probably notice by yourself if you run the examples. The GridFrame, GridFrameControler, DetailFrame, DetailFrameControler etc classes are not really generic. There are a lot of dependencies bult in and you will have to customize them again and again for every single implementation (can be seen in the demos).
I had another approach, I invested some time in building my own classes which are generic and using the unchanged OpenSwing classes in the background first. Now I’m only setting the properties file where all details are pre-defined. The rest is generic and I don’t have to re-code again and again for every single frame.
I hope this will help.
Regards
I used the openswing in team for more than two years.
It's a pretty nice swing framework for the enterprise development used in the Internal.
It provide great component based by MVP pattern ,such as grid , document ...
If you try it , It's a good article for you about Model-View-Presenter
And try the demo in the source,It's quite good.
The JAllInOne is also a good demo for the framework also made by the mcarniel
and It's a personal project only developed by mcarniel. Thanks mcarniel's great work.
i'm assigned to research something about how to use “addons” on building a program.
Basically, I have one main program that checks for the available components (ocx, dll, etc). Depending on what components there are, it will dynamically create the menus and load the components.
is this possible using .net Framework 2.0 or later
I think you might be looking for the word "plugin" and it is definitely possible with .Net.
For example: http://www.codeproject.com/KB/dotnet/PluginManagerClassBrk.aspx
One thing you could check out is the Microsoft Enterprise Library "Composite UI Application Block." This framework is designed to help build GUIs by combining separate UI components by composing them together based on various conditions.
I'm not sure if I'm a huge fan - it's pretty complicated and seems clunky to work with, but if you work through some of the examples, it might be worth looking into.
http://msdn.microsoft.com/en-us/library/aa480450.aspx