Turn on thread page Beta
    • Thread Starter
    Offline

    0
    ReputationRep:
    I'm currently taking a caurse in Software Engineering. From the course, it states that Software engineers wants to create Software that is reusable and component based. How do they acheive that? What language they have to use to make it 'reusable'?
    Offline

    14
    ReputationRep:
    Any language can be used to make reusable code. Really it just means you write your code in a way that allows it to be easily separated from that specific application and can be used for other things. Some languages make this easier, but it can be done with anything.
    Offline

    0
    ReputationRep:
    It's like Psyk says - it's all down to how you write your code.
    Breaking it down into useable chunks rather than monolithic programming.
    It can be a pain in the arse the first time you write something as the temptation is just to keep coding but if you stop and split things up then eventually you can find that the smaller bits of code can be re-used later on - either in the current project or on something else.

    .dlls have a similar ethos but at a much greater level so dont think you have to start writing them - these are very low level programming events that you should not need to worry about
    Offline

    1
    ReputationRep:
    Object Oriented programming makes it easy to make reusable code, because it is possible to make very generic Classes which could be easily be reused in other projects.

    For example if I was creating a Java Swing GUI and wanted a JTextField to allow the user to enter an Integer. I could just use a normal JTextField and when I need to get the integer, parse the text content from the field.
    Alternatively, I could make a new class called JNumberTextField which extends JTextField and encapsulates the parsing process inside a method called getInt().

    The second option immediately makes reusable code, since the Class can be dropped into any project and be instantly used. This ability to easily drop and use classes in other projects is what makes OO code reusable, and is only easily possible for classes that are fairly independant from other project specific classes (that is they do not reference other project specific classes). You can describe these independant reusable classes as loosely coupled. If you google loose coupling you should get some good infomation on reusable code.
    • Thread Starter
    Offline

    0
    ReputationRep:
    nice explaination Baron but can you explain about this one:

    (Original post by Baron)
    This ability to easily drop and use classes in other projects is what makes OO code reusable, and is only easily possible for classes that are fairly independant from other project specific classes (that is they do not reference other project specific classes). You can describe these independant reusable classes as loosely coupled.
    what do you mean by "project specific classes"? can give some examples like before? owh can C programming achieve this 'reusability' concept (easily)?

    thanks
    Offline

    0
    ReputationRep:
    You can produce reusable code in any language, the idea being to a very generic piece of code or library which you can then use in multiple projects. It's very much related to abstraction with the idea of breaking parts of a project into their own individual parts and having the various different classes of a program loosely coupled together (presuming it's written in an object-oriented language). This can help classes to be reusable if they have very little reliance on other aspects of the program.

    The only examples I can think of are when I've made games. If I ever want to make a game I have to make a JFrame, make images to be the front and back buffer, sort out how the front buffer is drawn to the frame, sort out what happens when I resize (or just turn that feature off), make various drawing methods for the JFrame (for drawing text, shapes, images, clearing the screen and flipping the buffers), sort out controls, and lots of other stuff.

    Essentially that is pretty easy to do, but I don't want to do it for every project.

    So instead I made a few classes where all that work is wrapped up for me into a GraphicsWindow class (there are also Controls and GraphicsImage classes too). It just makes my life a lot easier if I can make that graphics code once and then just import it into any new project.

    There is an interesting article on scalability here. Although it's more about what characteristics of a language make it good for producing a large program, rather then what helps to create reusable code, some of his points still apply. Namely when he is talking about abstraction. Either way, it's still an interesting read.
    Offline

    2
    ReputationRep:
    Object-orientation is not the only mechanism to make reusable software.

    "Pipes", both in the traditional Unix-style and more Internet-bound pipes like XML pipelines and even just REST-based Web services.

    Let me give you an example. I do a lot of work building stuff with the following sort of workflow:
    1. Get data in from messy source (eg. HTML, generic XML format, unreliable API, screen scraper etc.)
    2. Extract data from it.
    3. Construct into XML format.
    4. Transform XML into various varieties of outputs.

    Now, I could do all of that in one programming language. I've found Python to be a good way of doing that. But that isn't really the best way.

    The first step is to have all of the functions you run available as private APIs. Two of the ones I have set up are a caching system and an install of Tidy. If I have a URL, I can pipe it through the cache using either methods in, say, PHP, or I can just use a private REST API to get the stuff in. The latter isn't perfect, as, for instance, authentication breaks. But it serves as a neat bit of glue to get out of a jam.

    Then I use a system I've written called ArrayML to get the data from a PHP native associative array into a generic XML representation of it - literally just an XML version of a PHP associative array.

    Then I can send that XML to XSLT. Now, this is a far better way of doing it - since XSLT is designed to handle XML far better than most programming language's terrible XML module. There are limits to the number of times I can write "foreach ($item as $document->getEementsByTagName("foo"))" loops, and, worse, createElement, createTextNode and an infinite abyss of appendChild imperatives.

    This isn't a traditional object-oriented programming architecture - it's a hackier, "Webbier", held-together-with-sticky-tape type architecture, but it works. And it saves a lot of coder time, which is of the essence if you are not coding for money...

    Oh, and suggestions that I use Ruby instead will be filed in /dev/null. Yah. Get a language with proper Unicode support... heh.
    Offline

    1
    ReputationRep:
    (Original post by Jubrits)
    nice explaination Baron but can you explain about this one:



    what do you mean by "project specific classes"? can give some examples like before? owh can C programming achieve this 'reusability' concept (easily)?

    thanks
    When I said project specific classes I meant classes that are unlikely to be useful in other projects. For example if you were making a Hotel Booking System they might be classes such as; Hotel, HotelRoom etc.

    Any classes that reference these classes, won't be easily reusable since you couldn't simply drop them in another project which has nothing to do with Hotels.

    Like people have said, the idea of resuable code is not OO specific and can be applied with procedural languages such as C. OO just makes it easy to do so.
 
 
 
Reply
Submit reply
Turn on thread page Beta
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: July 19, 2007
Poll
Black Friday: Yay or Nay?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.