Good Dareware ---- Object-oriented Tools Try

zhaozj2021-02-17  42

Kindness

---- object-oriented tools chopper small test of: HolyFire first to introduce the first UML ---- Unified Modeling Language, which is an open standard modeling language, I want to introduce it in class view. The relevant part, that is, the illustration of the category in UML.

Rational Rose ---- Using UML tools, you can get free of charge on the Rational's website, 50M size of the 2000 version, get its connection is ftp: //ftp.rational.com/public/rose/rose2000win/rose2000nt/ Releases / RationalRose2000EnterpriseEdition.exe Whether it is an object-oriented or oriented process, we need tools to make us do better. When we use C , we can keep a clear mind when we can keep a clear mind to clarify their relationship. Can we imagine what they are, people are always limited, people always like to be lazy, we need to be tired of object-oriented programming, but more easily and convenient ways. It will be aware of the good things. There is a good tool to make people half-measures, I said the purpose of this sentence wants to tell you, I am not advertising now, but recommend a good tool to you.

The diagram is divided into three parts: head ---- used to express the name of the class 2: Information ---- Used to indicate the attribute of the class 3: Behavior ---- Method used to indicate the class There is also a small icon in front of the attribute / method, indicating their visibility, and PRIVATE, PUBLIC, and protected in C . When the attribute is declared in C , of course, the type is given, a method (that is, functions)

The corresponding C code above is Class Class {

Private:

int attrib;

PUBLIC:

Int Operation (int Arg = 0);

}

In the Rational Rose tool, you can easily finish these jobs, enter the names of the class, the properties and methods of the class, then double-click, modify the types and methods of the type and method of the property, and the return value type, point a few single sheets. The box, press OK, then the screen shown in the above figure appears. Then, you selected menu Tools -> C -> Code generation will generate two files, class.h and class.cpp, let us open it. After some other information, we left our concern. Class.h content #ifndef class_h

#define class_h 1 Class Class

{

PUBLIC:

// ## Constructors // This is a default constructor

Class ();

Class (const class & right); // This is a copy constructor

// ## Destructor (generated) // This is a destructor

~ Class ();

/ / ## Assignment Operation (%)

Class & Operator = (const class & right); // This is assigning copy function

// ## Equality Operations (%)

INT Operator == (const class ") const; // This is an equivalent comparison function

INT Operator! = (const class & right) const; // does not equivalent comparison function // ## ot ot ot er er斯斯斯 (specified)

INT Operation (int Arg = 0); // We define functions

Private:

// ## Get and set Operations for class attributes (generated)

Const int GET_ATTRIB () const; // reads the function of our defined attribute

Void set_attrib (int value); // Write functions for our defined properties

Private: // ## Implementation

// Data MEMBERS for Class Attributes

INT Attrib; // We define properties

}

// Class Class

/ / Read the entity of the function of our defined attribute

Inline const Int class :: get_attrib () const

{

Return Attrib;

}

// Entity to write our defined attributes

Inline void class :: set_attrib (int value)

{

Attrib = value;

}

#ENDIF

Class.cpp content

// Class

#include "class.h"

// Class Class

/ / Default constructor entity

Class :: Class ()

{

}

/ / Copy constructor entity

Class :: Class (Const Class & Right)

{

}

// Decorative entity

Class :: ~ class ()

{

}

// Entity to assign a copy function

Class & Class :: Operator = (Const Class & Right)

{

}

// Equal comparative function entity

INT Class :: Operator == (const class & right) const

{

}

// Do not equivalence comparison function entity

INT Class :: Operator! = (const class & right) const

{

}

/ / Customized function Operation entity

INT Class :: Operation (int Arg)

{

}

You can set the option to generate a class to remove some things you don't want or add what you want. In fact, the purpose of using this tool is not to automatically generate code. In fact, what you see is much more than listed above, if you don't want to turn the code back to the class map in the ROTIONAL ROSE project, those additives are really cumbersome . But the advantage is that we can see what properties and methods in the class, you can carefully think about their design and hit, the entire class constructor is visualized. Now we have used the UML diagram to represent a simple class. The virtual function is a key point in C , how to represent a category with virtual functions in the UML diagram. In the Rational Rose Tool, we double-click the Class icon, double-click Operation in the Operations column, change OperationKind to Virtual confirmation in the C column, that is. Let's take a look at the generated code class.h

#ifndef class_h

#define class_h 1

Class Class

{

PUBLIC:

// ## Constructors (generated)

Class ();

Class (Const Class & Right);

// ## Destructor (generated)

~ Class ();

// ## Assignment Operation (generated) Class & Operator = (const class & right);

// ## Equality Operations (%)

INT Operator == (const class & right) const;

INT Operator! = (const class & right) const;

// ## taher operations (specified)

// ## Operation: Operation% 3Be1e77E0237

Virtual Int Operation (int Arg = 0);

}

// Class Class

#ENDIF

So someone wants to ask, how to define static member variables, I have introduced this is a very useful technology. Of course, you will not let you down, let's introduce how to represent static member variables.

Seeing it, there is more than a $ symbol, wow, this is not too simple, but is it complicated? Similarly, in the Rational Rose Tool, we double-click the Class icon, double-click Attributes column, and select Static in the Detail column. In order to see clearly, this time I dropped other information. Class.h #ifndef class_h

#define class_h 1 Class Class

{Private: // ## Implementation

// Data MEMBERS for Class Attributes

Static int attrib;}; #ENDIF is now inherited to the game. Let us look at how the UML graphic represents a class and class inheritance. That is, subclasses use a hollow arrow to point to the parent class. But UML did not indicate which inheritance is private, public, which is in protected, so I have to marke it. In the Rational Rose Tool, we drag two CLASS in the class view, named A and B, dragging out a generalization from B, pressing the right button on the arrow, found there is public inheritance, private inheritance, protected inheritance Optional, there is also possible to check Virtual Inheritance. Let's take a look at what is the resulting code? #Ifndef b_h

#define b_h 1 // a

#include "a.h" Class B: public a // ## inherits: % 3BE1EFB0039D

{

}; #ENDIF is too easy. Very good, we continue to see how aggregation in the association means that weak aggregation means that a pointer contains B, and their relationship is not very close, A is not related to B when creating and destroyed. Strong aggregation means A contains a entity that contains B, and when B is created, B is creating, and the B does not exist. Let us look at the generated code, and the fact is often convincing. Weak aggregation A.h #ifndef a_h

#define a_h 1

// b

#include "b.h" Class A

{

// ## Get and set Operations for associations // ## association: % 3Be1f3bb0250

// ## role: a :: % 3Be1f3bd02ad

Const b * get_the_b () const; void set_the_b (b * value); private: // ## importation

// data members for associations b * THE_B;

}; // Class a inline const b * a :: get_the_b () const

{

Return THE_B;

} inline void a :: set_the_b (b * value)

{

THE_B = Value;

} #ENDIF strong polymer time A.H // B

#include "b.h" Class A

{

Private: // ## Implementation

// Data Members for Associations // ## association: % 3Be1f3bb0250

// ## begin a :: % 3Be1f3bd02ad.Role Preserve = no public: b {-> vhgn}

B THE_B;}; // Class a inline const b A :: get_the_b () const

{

Return THE_B;

} inline void a :: set_the_b (b value)

{

THE_B = Value;

} #ENDIF now let us look at a problem, one can use a variety of tools, and the tool can be used by a variety of people, it is obvious, this is a multi-to-many relationship, just use the association. Very good solution to this problem, the solution is to add an associated class, and he determines at a moment in a relationship, one person corresponds to a tool. See what the generated code is? Howmanusetool.h #ifndef hoWmanuseTool_H

#define howmanusetool_h 1 Class Tool;

Class Man; Class HowmanuseTool

{

PUBLIC:

String DOIT ();

Const Tool * get_the_tool () const;

Void set_the_tool (Tool * Value); Const Man * get_the_man () const;

Void set_the_man (man * value); private: // ## importation

Tool * the_tool;

MAN * THE_MAN;

}; // class howmanusetool inline const {*ManuseTool :: get_the_tool () const

{

Return the_tool;

} inline void howmanusetool :: set_the_tool (Tool * Value)

{

THE_TOOL = VALUE;

} inline const man * howmanusetool :: get_the_man () const

{

Return THE_MAN

} inline void howmanusetool :: set_the_man (man * value)

{

THE_MAN = VALUE;

} #ENDIF hoWmanusetool.cpp #include "HowmanuseTool.h"

#include "Tool.h"

#include "man.h" String HowmanuseTool :: DOIT ()

{

} What we have to do is

String howmanusetool :: DOIT () {

/ / Plus a sentence

RETURN THE_MAN-> WHO () "use the" the_tool-> what ();

} Ok, now we told a lot of ways to use the UML graphic to perform object-oriented design, should be time to make readers to digest. 2001/10/28 Ding Ning

转载请注明原文地址:https://www.9cbs.com/read-28789.html

New Post(0)