zby,
I'm not sure what you mean when you say that your whole application is just one object and the runmodes it's methods. But I will agree with you for the moment. And illustrate what I think is your point.
I like the main code for my bigger applications to be:
use App::Class;
App::Class->new()->run();
And then, inside my application any external interface
with the application is done calling App::Class methods. That means, obviously, that all my
run modes are methods of my class.
But I will not write all the code for my application. I'll use code others (or myself) did writen in other instances. Code for specific functions.
For instance, I'll use a module I had written that extends
Config::Tiny. See the readconfig for
App::Class:
use Config::myTiny;
sub readconfig {
my $self=shift;
my $cfg=$0;
$cfg=~s/\.pl$/.ini/;
my $conf=Config::myTiny->read($cfg);
$conf=Config::myTiny->new() unless $conf;
$self->{config}=$conf;
}
Now, whener I need to get a config variable, I'll use
$self->{config} like this:
sub run {
my $self=shift;
$self->readconfig();
# ...
if ($self->{config}->get('options','showonstartup')) {
$self->show_mainwindow();
}
# ...
}
So, you application will be a single class, but you should break your code to create smaller complete and independent objects, that you will use in the code for your main application.
OoP allow you other things also. If you have (or intent to have) several application that use identical functionalities as their base, you can create a base class that implement those functions and extend that using it as base for every other application.
I think that this are the most simple and easier ways to use OoP that can help you reduce your codebase, improve your code, as the code you reuse frequently will tend be corrected faster (assuming you use the same code, not that you copy it from project to project), and get your applications running faster.
Remember...
- use base qw(Your::Base::App);
- if you can isolate something, you can turn it into an object
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.