0% found this document useful (0 votes)
29 views31 pages

SE1-Lecture - 3 - UML

Uploaded by

WoloWizard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views31 pages

SE1-Lecture - 3 - UML

Uploaded by

WoloWizard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

‫جامعة تشرين‬

‫كلية الهندسة المعلوماتية‬


‫قسم البرمجيات ونظم المعلومات‬

‫هندسة برمجيات ‪1‬‬

‫_‪_UML Part‬‬

‫د‪ .‬باسل حسن‬

‫الفصل الدراسي الثاني ‪2020 / 2019‬‬


‫مخطط الصفوف‬
‫‪Class Diagram‬‬

‫هندسة برمجيات ‪1‬‬ ‫‪-2-‬‬


‫مخطط الصفوف ‪Class Diagram‬‬

‫• تُستخدم مخططات الصفوف لنمذجة البنية الساكنة للنظام‪ ,‬بحيث تصف عناصر النظام والعالقات‬
‫بينها‬

‫• في سياق البرمجة الغرضية التوجه (‪ ،)OOP‬يصور مخطط الصفوف الصفوف التي يتكون منها‬
‫النظام البرمجي والعالقات بين هذه الصفوف‬

‫• يمكن استخدام مخطط الصفوف أيضا‬


‫– لتوليد كود البرنامج بشكل أوتوماتيكي (‪)Automatic Code Generation‬‬
‫– ألغراض التوثيق (‪)Documentation‬‬

‫• لتمثيل حاالت من الصفوف التي تم تصميمها في مخطط الصفوف يتم استخدام مخطط األغراض‬
‫‪Object Diagram‬‬

‫هندسة برمجيات ‪1‬‬ ‫‪-3-‬‬


UML Class Notation - UML ‫ترميز الصف في‬

Class Name

Attributes
{readOnly}
= "Syria"

Operations

:‫) يمكن تضمين مايلي‬Attribute( ‫• لتعريف صفة‬


Visibility Name : Type Multiplicity = default {Property}

‫!يجب أن تتضمن الصفة االسم على األقل‬

1 ‫هندسة برمجيات‬ -4-


‫ الرؤية‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

‫• تُوضع عالمة من العالمات التالية قبل اسم الصفة لتوضح مجال رؤيتها (مشابهة لمحددات‬
: ‫ مثال‬Java ‫) في‬Access Specifiers ‫الوصول‬
public + ▪

private - ▪

protected # ▪

package ~ ▪
1 ‫هندسة برمجيات‬ -5-
‫‪ - Attribute Syntax‬الصفات المشتّقة‬
‫}‪Visibility / Name : Type Multiplicity = default {Property‬‬

‫}‪{readOnly‬‬
‫"‪= "Syria‬‬

‫• هذه العالمة توضح أن هذه الصفة مشتقة من غيرها من الصفات‬

‫• يمكن إضافة مالحظة (‪ )Note‬لوصف كيفية اشتقاق هذه الصفة‬


‫‪ -‬مثال‪ age :‬مشتقة من ‪dob‬‬

‫هندسة برمجيات ‪1‬‬ ‫‪-6-‬‬


‫ االسم‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

‫• اسم الصفة‬

1 ‫هندسة برمجيات‬ -7-


‫ النمط‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

:‫) يمكن أن يكون‬Type( ‫• النمط‬


Date ‫ مثل‬,)User-defined classes( ‫▪ صفوف معرفة من قبل المستخدم‬
)Data Type( ‫▪ نمط بيانات‬
integer ‫ مثل‬,)Primitive data type( ‫األنماط البدائية‬ o

,)Enumerations( ‫األنماط التعدادية‬ o


Semester ‫مثل‬
1 ‫هندسة برمجيات‬ -8-
‫ التعددية‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

‫• تصف عدد القيم التي يمكن لصفة أن تحتويها‬


1 ‫• القيمة اإلفتراضية‬
[min..max] •

1 ‫هندسة برمجيات‬ -9-


‫ القيمة االفتراضية‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

‫• قيمة افتراضية لصفة‬

1 ‫هندسة برمجيات‬ - 10 -
‫ الخصائص‬- Attribute Syntax
Visibility / Name : Type Multiplicity = default {Property}

{readOnly}
= "Syria"

:‫المعرفة مسبقا‬
ّ ‫ ويمكن أن تأخذ القيم التالية‬,‫• لتعريف خاصة (أو خصائص) لصفة‬
,{ordered} ,{non-unique} ,{unique} ,{readOnly}
{unordered}
{unique, readOnly} :‫• يمكن أن نشمل أكثر من خاصة كمايلي‬

1 ‫هندسة برمجيات‬ - 11 -
‫‪ - Operation Syntax‬الوسطاء و نمط اإلعادة‬

‫}‪{readOnly‬‬
‫"‪= "Syria‬‬

‫‪:void‬‬

‫• ‪ )input parameter( in‬تمرير قيمة للـ ‪ - Operation‬التمرير بقيمة‬


‫• ‪ )output parameter( out‬بعد تنفيذ الـ ‪ Operation‬يمكن تحديث الوسيط بقيمة جديدة (كخرج)‬
‫‪ -‬التمرير بمرجع‬
‫• ‪ – inout‬يمكن للوسيط أن يكون كوسيط دخل أو خرج‬
‫هندسة برمجيات ‪1‬‬ ‫‪- 12 -‬‬
‫‪Class Variable and Class Operation‬‬

‫• ‪ Class Variable‬يُعرف مرة فقط لكل صف‬


‫‪ -‬وهو يمثل الـ ‪ static variables‬في لغات البرمجة‬

‫}‪{readOnly‬‬ ‫• ‪ Class Operation‬يمكن استخدامها بدون‬


‫"‪= "Syria‬‬ ‫إنشاء غرض‬
‫‪ -‬يمثل الـ ‪ static methods‬في لغات البرمجة‬

‫• تُمثل بوضع خط تحت تعريفها كما في المثال جانبا‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 13 -‬‬


Code Generation

class Person {
public String firstName;
public String lastName;
private Date dob;
private int age;
private final int nationalIdNumber;
protected String[] address = {"Syria"};
{readOnly} public static int counter;
= "Syria"
public Date getDob() {...}

public int getNationalIdNumber() {...}

public static int getCounter() {...}


}

1 ‫هندسة برمجيات‬ - 14 -
‫تمثيل الصف بمستويات مختلفة من التفاصيل‬

Grade of details

Person
firstName
lastName
dob
getNationalIdNumber()
getCounter()

1 ‫هندسة برمجيات‬ - 15 -
‫العالقات بين الـصفوف ‪ -‬عالقة الربط ‪Association‬‬
‫‪Binary Associations‬‬
‫‪Association name‬‬ ‫‪Reading direction‬‬
‫‪Navigability‬‬

‫‪X‬‬

‫‪Visibility‬‬ ‫‪Role‬‬
‫قابلية التنقل (‪)Navigability‬‬ ‫•‬
‫تشير قابلية التنقل إلى أن الغرض (‪ )Object‬يعرف أغراض شريكه‪ ,‬وبالتالي يمكنه الوصول إلى الـ‬
‫‪ attributes‬و الـ ‪ operations‬المرئية الخاصة بهذه األغراض‬
‫‪ -‬في المثال أعاله إلى أنه يمكن للطالب الوصول إلى الخصائص المرئية لألساتذة الذين يحضرون‬
‫محاضراتهم‪ .‬في المقابل‪ ،‬ال يمكن لألستاذ الوصول إلى الخصائص المرئية للطالب الذين يحضرون‬
‫محاضرته‬
‫• التعددية (‪) Multiplicity‬‬
‫عدد األغراض التي يمكن أن ترتبط مع غرض واحد من الجهة المقابلة‬
‫• الدور (‪) Role‬‬
‫يشير الدورإلى الطريقة التي يشارك بها الغرض في عالقة الربط ‪ ،‬أي الدور الذي يلعبه في العالقة‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 16 -‬‬


Association ‫ عالقة الربط‬- ‫العالقات بين الصفوف‬
Binary Associations as Attribut

class Professor {…}

class Student{
public Professor[] lecturer;
…}

1 ‫هندسة برمجيات‬ - 17 -
‫العالقات بين الصفوف ‪ -‬عالقة الربط ‪Association‬‬
‫‪Binary Associations – Further Exampels‬‬

‫‪ -‬المحاضر يدرس مقرر واحد على األقل‬


‫‪ -‬المقرر يُعطى من قبل محاضر واحد على األقل‬

‫‪ -‬االمتحان يمكن أن يكون إما في مكتب أو في قاعة محاضرات‬


‫وال يمكن أن يكون في االثنين معا‪.‬‬
‫‪ -‬في هذه الحالة يحب إضافة قيد (‪{xor} – )Constraint‬‬

‫‪Unary(or reflexive) Associations – An Example‬‬

‫‪ -‬الشخص يتبنى الدور ‪ examiner‬أو ‪examinee‬‬


‫‪ -‬هذا النموذج اليستثني أن الشخص يمكن أن يمتحن نفسه!‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 18 -‬‬


Association ‫ عالقة الربط‬- ‫العالقات بين الصفوف‬
N-ary Associations
Situation: One specific exam with one specific lecturer can be taken by any
number of students and one specific student can be graded by one specific
lecturer for any number of exams.

Ternary
association

X Source: (Seidl M. et al.,2015)

1 ‫هندسة برمجيات‬ - 19 -
‫صفوف الربط ‪Association Classes‬‬

‫}‪{non-unique‬‬

‫• تستخدم صفوف الربط في تعيين صفات (‪ )attributes‬أو عمليات (‪ )operations‬للعالقة بين‬


‫الصفوف (أي تقدم صفوف الربط معلومات إضافية عن عالقة الربط)‬
‫• يمكن أن ترتبط صفوف الربط مع صفوف أخرى‬

‫• في المثال أعاله‪ ,‬في حال إضافة }‪ ,{non-unique‬يمكن للموظف أن يملك أكثر من عقد‬
‫عمل مع نفس الكلية‬
‫‪ -‬في حال حذفها‪ ,‬تكون القيمة اإلفتراضية }‪{unique‬‬
‫هندسة برمجيات ‪1‬‬ ‫‪- 20 -‬‬
‫العالقات بين الصفوف ‪ -‬عالقة التجميع ‪Aggregations‬‬

‫التجميع هو شكل خاص من أشكال الربط يستخدم للتعبير عن أن أغراض (‪ )Objects‬لـ صف (‪)Class‬‬ ‫•‬
‫هي أجزاء من من أغراض لصفوف أخرى‪ .‬يوجد نوعان من التجميع في ‪:UML‬‬
‫‪ -‬التركيب (‪)Composition‬‬
‫‪ -‬التجميع المشترك (‪)Shared Aggregation‬‬

‫‪VS‬‬
‫‪Composition‬‬ ‫‪Shared Aggregation‬‬

‫• يوجد تبعية وجود (‪)existence dependency‬‬ ‫• ال يوجد تبعية وجود ( ‪)existence dependency‬‬
‫بين عناصر ‪ A‬و‪B‬‬ ‫بين عناصر ‪ A‬و ‪B‬‬
‫‪ -‬إذا ُحذف ‪ ,B‬يتم حذف ‪A‬‬ ‫‪ -‬إذا ُحذف ‪ ,B‬ال يتم حذف ‪A‬‬
‫‪ -‬ارتباط قوي (‪)strong belonging‬‬ ‫‪ -‬ارتباط ضعيف (‪)weak belonging‬‬
‫• التعددية (‪ )multiplicity‬على جهة ‪ B‬يمكن أن‬ ‫• التعددية (‪ )multiplicity‬على جهة ‪ B‬يمكن أن تكون‬
‫تكون ‪ 1‬كحد أقصى‬ ‫أكبر من ‪1‬‬

‫• عالقة انتقالية وغير متطابقة‬ ‫• عالقة انتقالية وغير متطابقة‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 21 -‬‬


Aggregations ‫ عالقة التجميع‬- ‫العالقات بين الصفوف‬
Shared Aggregations
Examples

class StudyProgram {
private List<Course> courses;
…}

Compositions

class Building {
private final LectureHall[] lectureHalls;

Building(int numberOfLH) {
lectureHalls = new LectureHall[numberOfLH];
for (int i = 0; i < numberOfLH; i++)
lectureHalls[i] = new LectureHall("LH" + i);
}
…}
1 ‫هندسة برمجيات‬ - 22 -
Generalizations ‫ عالقة التعميم‬- ‫العالقات بين الصفوف‬

‫) و الروابط‬Attributes and Operations( ‫توضح عالقة التعميم أن الخصائص‬ •


)Subclasses( ‫) تنتقل إلى صفوفه الفرعية‬Superclass( ‫) لصف عام‬Associations(
:‫ تسمى هذه العالقة أيضا‬-
Inheritance o
“Is a” relationship o

Generalization notation •

Subclass Superclass

1 ‫هندسة برمجيات‬ - 23 -
Generalizations ‫ عالقة التعميم‬- ‫العالقات بين الصفوف‬

An Example

Without Generalization

With Generalization

1 ‫هندسة برمجيات‬ - 24 -
‫العالقات بين الصفوف ‪ -‬عالقة التعميم ‪Generalizations‬‬

‫‪Abstract Class‬‬
‫• تستخدم لإلشارة إلى عدم إمكانية إنشاء أغراض بشكل مباشر من الـ ‪superclass‬‬
‫• يتم اإلشارة إلى الـ ‪ abstract class‬بطريقتين‪:‬‬
‫– }‪ {abstract‬قبل اسم الـ ‪ ,class‬أو‬
‫– كتابة اسم الـ ‪ class‬بخط مائل‬

‫!‪No Person-object possible‬‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 25 -‬‬


Abstract Classes vs. Interfaces

interface Printable{
void print();
}

class Person implements Printable{


...
public void print() {
...
}
}

class Student extends Person {


...
@Override
public void print() {
...
}
}

1 ‫هندسة برمجيات‬ - 26 -
An Example - Class Diagram ‫مخطط الصفوف‬
Enumeration

Data type

1 ‫هندسة برمجيات‬ - 27 -
‫مخطط األغراض ‪Object Diagram‬‬

‫• يشار إلى العالقات بين األغراض بالروابط (‪)links‬‬


‫• تتضمن خصائص الغرض خصائصه الهيكلية (الصفات والعمليات ‪)attributes and operations‬‬
‫• غالبا ال يتم وصف العمليات‪ ,‬ألنها متطابقة لجميع الكائنات من صف‪ ,‬ولذلك يتم وصفها في مخطط‬
‫الصفوف فقط‬

‫❖ مخطط األغراض يمثل صورة (أو ‪ )Snapshot‬من األغراض في لحظة معينة من الزمن‪ ,‬ولكن يمكن أن‬
‫تتطور األغراض وتتغير مع مرور الوقت‬

‫هندسة برمجيات ‪1‬‬ ‫‪- 28 -‬‬


3 / 1 - ‫ملخص‬

Name Notation Description

Description of the structure and


Class
behavior of a set of objects

oder

Abstract class Class that cannot be instantiated

Relationship between classes:


navigability unspecified,
Association
navigable in both directions,
not navigable in one direction

http://www.uml.ac.at/en/lernen :‫المصدر‬

1 ‫هندسة برمجيات‬ - 29 -
3 / 2 - ‫ملخص‬

Name Notation Description

n-ary Relationship between n (here 3)


association classes

More detailed description of an


Association class
association

An object of C is in a relationship
xor relationship with an object of A or with an
object of B but not with both

http://www.uml.ac.at/en/lernen :‫المصدر‬

1 ‫هندسة برمجيات‬ - 30 -
3 / 3 - ‫ملخص‬

Name Notation Description

Shared Parts-whole relationship (A is part


aggregation of B)

Strong
Existence-dependent parts-whole
aggregation =
relationship (A is part of B)
composition
Inheritance relationship (A
Generalization
inherits from B)

Object Instance of a class

Link Relationship between objects

http://www.uml.ac.at/en/lernen :‫المصدر‬

1 ‫هندسة برمجيات‬ - 31 -

You might also like