Tutorial :What design patterns should I use for a lightweight IDE?



Question:

I'm writing a lightweight IDE. I chose Ruby+Gtk2 for the task. I already have a minimal prototype for it, but right now, most of the code is inside my window class. I'll soon start working on the "real deal", but I would like to know what design patterns should I make use of. I'm planning for plugin support too, so that the app will be extensible. Any ideas are welcome, but please discuss your option a bit.

Please keep in mind this is a scripting language. I'm not sure if all of Java's design patterns apply here.


Solution:1

Design patterns are solutions for common problems. What problems are you having? In consulting work, we see that often when someone sets out saying "Okay, here's my idea. What design patterns can I put to work?," the architecture gets overly complicated very quickly.

Instead of looking for design patterns that you could possibly use, read up on design patterns (I hate to link to Wikipedia, but their article does have a good list to get you started on other searches with at least) and then apply them when you come up with a problem that fits their criteria.

As far as having a lot of code in your window class, that may be appropriate for your application, or you may want to look at something like a loose MVC pattern. Generally for GUI programming, a rigid MVC is going to be too strict, and require too much work for "true" separation of concerns.

There are many common problems that can be solved without design patterns, and that does not mean the solution is right or wrong. Plugin support, for instance, is very often given just by supplying a plugin interface or a set of events a plugin can respond to. Alternatively, you could look at the Adapter pattern.


Solution:2

I'm not sure if this will be much help, but the book "Design Patterns in Ruby" talks about, well, design patterns in ruby and how they might differ from Java's design patterns.


Solution:3

Also, don't forget to check out existing IDEs. What did they use?

Since editing will be a component of your IDE, you should check up on actual open source editors.


Solution:4

Just to clarify a possible misunderstanding: Are you perhaps referring to UI patterns (as opposed to software architecture design patterns)? Your question seems to me to make more sense that way.


Solution:5

I'm not sure if this is appropriate, but there's a nice book about disecting & building an IDE in C#. The book does discuss about the design patterns being used to develop the Sharp Develop IDE. SharpDevelop is a nice IDE & it's open source you might want to have a peek at this book & home page for Sharp Develop.


Solution:6

The best way to design a ruby GUI application is to use visualruby:

http://visualruby.net

You can make your GUI totally separate from your classes. For example, If you want to create a GUI for the following class, you can do it easily without disturbing it:

class DataObject      def initialize(name, address, email, phone)      @name = name      @address = address      @email = email      @phone = phone    end    end  

You create a GUI for this class by subclassing it, and adding the GUI:

class DataObjectGUI < DataObject      include GladeGUI      def show()      load_glade(__FILE__)  #loads glade/DataObjectGUI.glade into @builder      set_glade_all() #populates glade controls with insance variables from DataObject       show_window()     end       end  

The GladeGUI interface contains all the GUI magic. The load_glade() method will load the file, DataObject.glade. This is a glade form that contains Gtk::EntryBoxes named,name, address, phone and email. The form will show on the screen with all the fields filled-in.

Obviously the show_window() will make the window appear on the screen. The destroy window is automatically called by GladeGUI when you click the "x" button.

This disign pattern can be used for any class. A good example is if you have an ActiveRecord class, and you want to show the record on the screen. You just subclass as above, and it's editable and savable.

This example is taken from one of the example projects on visualruby.net.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »