[ Pobierz całość w formacie PDF ]
.My intent, however, is to show you how to create components.You do not have tobe an expert in C++ OOP theory to achieve that goal.For all its wonders, I don't think there is anything in C++Builder that even approaches the significance of components.VCL components are the most amazing technological achievement I have seen in contemporary programming.If youwant to do something really fantastic with your computer, then pay attention to the next few chapters so that you canlearn how to build great components.When reading this chapter, you might want to make use of the ClassBrowser sample program that ships with BCB.Itallows you to explore the hierarchy of the VCL.This program is found in the Examples/ClassBrw directory.It isfar from perfect, but it will serve to give you an overview of the VCL classes.You should also go towww.object-domain.com and see whether they have a version of Snorkle for C++Builder available.The versionsof Snorkle for Delphi that I have seen are very nice indeed, and if they can duplicate their efforts in the world of C++,then most readers of this book will want to test their technology.About ObjectsIt might seem a little strange to start focusing on objects this late in the book.After all, almost every program I haveshown so far uses object-oriented code.So how could I wait this long to begin talking seriously about objects? Toanswer this question, I need to discuss two different issues:How does BCB treat objects?Why do people write object-oriented code?The developers wanted BCB to be very easy to use.By its very nature, OOP is not always a simple topic.As a result,BCB goes to considerable lengths to hide some of the difficulties of object-oriented programming from the user.Thebiggest steps in this direction include the automatic construction of Form1 as an object and the existence of thefile:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch19.htm (1 of 50) [10/10/2000 1:14:22 AM] Ch 19 -- Inheritancedelegation model.The fact that the scaffolding for most methods is produced automatically by the IDE is one of thekey ways the product saves time--and one of the key ways it eases the process of producing applications.The simple fact is that some people would never be able to approach BCB if they had to go through the process ofwriting all this every time they created a form://--------------------------------------------------------------------------#ifndef Unit1H#define Unit1H//--------------------------------------------------------------------------#include#include#include#include//--------------------------------------------------------------------------class TForm1 : public TForm{__published:private:public: // User declarationsvirtual __fastcall TForm1(TComponent* Owner);};//--------------------------------------------------------------------------extern TForm1 *Form1;//--------------------------------------------------------------------------#endifI'm leaving out the implementation of the constructor, and a few other features, but in a stripped-down form, this codeis indeed the basis for most BCB units.It's simple enough to write; nonetheless, it could form a barrier between theproduct and certain types of programmers.The next obvious question is, "Why did the developers choose to write object-oriented code if the subject itself can attimes become somewhat complex? Why not just use the relatively simpler framework provided by structuredprogramming?" The answer is that although it is simpler to create small structured programs than small object-orientedprograms, it's easier to write large object-oriented programs than it is to write large structured programs.OOP brings discipline and structure to a project.In the long run, this makes coding easier.The problem is the learningcurve associated with understanding OOP.Almost everyone agrees that it's easier to finish a group project if you appoint a leader for the group; it's easier to win atsports if you practice regularly; and, ultimately, it's easier to become a good musician if you sit through some boringfile:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch19.htm (2 of 50) [10/10/2000 1:14:22 AM] Ch 19 -- Inheritancelessons with a professional.It also might seem at first as if structured programs are simpler to learn how to write and,therefore, are simpler to write, but this isn't true.Just as it helps to take lessons, practice, and learn discipline if youwant to become good at playing a sport or a musical instrument, it helps to learn object- oriented code if you want towrite good programs.Here's another way of stating the same matter.There is nothing you can do with object- oriented code that you can'talso do with structured programming.It's just that OOP makes it relatively easy to construct programs that arefundamentally sound and easily maintained.This doesn't mean you can't write structured programs that are every bit asarchitecturally sound as object-oriented programs.The problem, however, is that it is very difficult to design astructured program that is truly modularized and truly easy to maintain.Object-oriented code, on the other hand, has anatural tendency to move you in the direction of a sound, well-structured design.The thesis of this chapter is that object-oriented code is basically a technique for designing robust, well-plannedprograms.The syntax of OOP emerged out of the desire to help programmers design applications that work.It isperhaps arguable as to whether or not OOP by itself succeeded in achieving its goal, though certainly I personallybelieve that it is a success.However, I think it is undeniable that OOP in conjunction with components is the answer tomany core programming problems.If your only experience with components is in creating ActiveX controls, then youhaven't yet seen what this technology can do.The combination of OOP and components is something that can makeprogrammers many times more productive than they had ever imagined possible when writing structured code, or whenworking with either objects or components alone.NOTE: It's probably worth pointing out that OOP is not a separate subject from structured programmingbut its natural child.OOP emerged out of the same types of thinking that generated structured code.Muchof what is true in structured programs is also true in object-oriented programs, except OOP takes thesetheories much further.Object-based programmers should know nearly everything that structuredprogrammers know and should then add another layer of information on top of it.OOP is certainly not the end-all and be-all of programming.Rather, it is an intermediate step in an ongoing process thatmight never have an end.BCB, with its heavy use of components, already shows part of what the future holds.Inparticular, the future is about components and visual manipulation of objects.The Object Inspector enables you to see inside objects and to start to manipulate them visually.You can do this withouthaving to write code.It is quite likely that this trend will continue in the future, and you will start to see programs notas code but as a series of objects depicted as a hierarchy [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • agnieszka90.opx.pl