Beruflich Dokumente
Kultur Dokumente
Tkinter (or any other python GUI toolkit! is not a re&uirement for the exam
Associations
In real life, there are lots of many'to'many associations In a software these (eneral associations complicate implementation and maintenance bidirectional association means that both ob)ects can be understood only to(ether It is important to constrain relationships as much as possible* Imposin( a traversal direction +ddin( a &ualifier, reduce multiplicity ,liminatin( nonessential associations
gr = ctr.assign("1", "FP", 10) assert gr.getDiscipline()=="FP" assert gr.getGrade()==10 assert gr.getStudent().getId()=="1" assert gr.getStudent().getName()=="Ion"
st = Student("1", "Ion", Address("Adr", 1, "Cluj")) rep = GradeRepository() grades = rep.getAll(st) assert grades 0!.getStudent()==st assert grades 0!.getGrade()==10
gr)#
a grade grade is in the repository GradeAlreadyAssigned exception if we already ha e a grade for the student at the gi en discipline raise !epository"xception if there is an I# error when writing to the file """ i" self."ind(gr.getStudent(), gr.getDiscipline())$=None# raise GradeAlreadyAssigned() %open t&e "ile "or append try# " = open(self.''"name, "a") grStr = gr.getStudent().getId()("$"(gr.getDiscipline() grStr =grStr("$"(str(gr.getGrade())("%n" ".)rite(grStr) ".close() e*cept I+,rror# raise Repositor,*ception("&na'le to write a grade to the file")
Data transfer objects -unctionality* #how the best . students at a (iven discipline/ #how a table containin( the name of the student and his (rade at the disicipline
$reate a new class that contains )ust the needed information to implement the re&uested functionality
Program testing
Testing is observin( the behavior of a pro(ram in many executions/ ,xecute the pro(ram for some input data and observe if the results are correct for these inputs/ Testin( does not prove pro(ram correctness (only (ive us some confidence!/ 0n the contrary, it may prove its incorrectness if one execution (ive wron( results/ Testin( can never completely identify all the defects within software/
Testing methods
"#hausti(e testing
$heck the pro(ram for all possible inputs/ Impractical so we need to choose a finite number of test cases/
2lack 2ox test case for a prime3not prime test case for 4 test case for ne(ative number
White 2ox (cover all the paths! test case for 4 test case fot ne(ative test case for 5 test case 6 test case for prime (no divider! test case for not prime
de" whiteBoxPrimeTest()# assert (is5rime(1)==0alse) assert (is5rime(1)==2rue) assert (is5rime(11)==2rue) assert (is5rime(7)==2rue) try# is5rime(83) assert 0alse e*cept .alue,rror# assert 2rue try# is5rime(0) assert 0alse e*cept .alue,rror# assert 2rue
de" blackBoxPrimeTest()# assert (is5rime(6)==2rue) assert (is5rime(7)==0alse) try# is5rime(83) assert 0alse e*cept .alue,rror# assert 2rue try# is5rime(0) assert 0alse e*cept .alue,rror# assert 2rue
Testing $e(e$s
Tests are fre&uently (rouped by where they are added in the software development process, or by the level of specificity of the test/
nit testing
Unit testin( refers to tests that verify the functionality of a specific section of code, usually at the function level/
Testin( unit of code in isolation (functions!/ Test small parts of the pro(ram independently
!ntegration testing
$onsiders the way pro(ram works as a whole/ +fter all modules have been tested and corrected we need to verify the overall behavior of the pro(ram/
Automated testing
Test automation is the process of writin( a computer pro(ram to do testin( that would otherwise need to be done manually/ use of software to control the execution of tests, the comparison of actual outcomes to predicted outcomes, the settin( up of test preconditions
TDD:
T%% #teps* 7 7 7 automated test cases writin( specification (inv, pre3post! 8 throwin( or not exceptions production code
Debugging
Debugging is the activity that must be performed when testin( indicates the presence of errors, to find errors, and rewrite the pro(ram with the purpose of eliminatin( the errors/ 7 usin( print statement 7 usin( I%, %ebu((in( is the most unpleasant activity/ %ebu((in( must be a(oided0
"c$ipse debug perspecti(e
Debug (ie wiew the current execution trace (stack trace! execute step by step, resume3pause execution 1ariab$es (ie view variable values
Program inspection
+ny fool can write code that a computer can understand/ Good pro(rammers write code that humans can understand Pro(rammin( style consist of all the activities made by a pro(rammer for producin( products easy to read, and easy to understand, and the way in which these &ualities are achieved
)aming con(entions:
7 7 7 7 class names* #tudent, #tudent"epository variable names* student, nr,lem (nr9elem! function names* (et:ame, (et+ddress, store#tudent ((et9name,(et9address, store9student! constants* +;
&efactoring
"efactorin( is the process of chan(in( the software system in such a way that it does not alter the external behavior of the code yet improves its internal structure/ It is a disciplined way to clean up the code that minimi1es the chances of introducin( bu(s/ When you need to add a new feature to the pro(ram, and the pro(ram<s code is not structured in a convenient way for addin( the new feature, first refactor the code to make it easy to add a feature, then add the feature
,hy to refactor
7 7 7 7 "efactorin( improves the desi(n of the software "efactorin( makes software easier to understand "efactorin( helps you find bu(s "efactorin( helps you pro(ram faster
*ad sme$$s
When we need to refactor the code
Dup$icated code Long method Large c$ass Long parameter $ist %omments Di(ergent change
0ne class is commonly chan(ed in different ways for different reasons
&efactoring 2 3ethods
&ename 3ethod
The name of a method does not reveal its purpose.
Decompose %onditiona$
=ou have a complicated conditional (if'then'else! statement/ ,xtract methods from the condition, then part, and else parts/
!n$ine Temp
You have a temp that is assigned to once with a simple expression, and the temp is getting in the way of other refactorings. &ep$ace a$$ references to that temp -ith the e#pression0
&efactoring 2 3ethods
&emo(e Assignments to Parameters
The code assigns to a parameter. se a temporary (ariab$e instead0
&efactoring 2 %$ass
"ncapsu$ate 4ie$d
There is a public field. 3a+e it pri(ate and pro(ide accessors0
"#tract 3ethod
You have a code fragment that can be grouped together. Turn the fragment into a method -hose name e#p$ains the purpose of the method0
3o(e 3ethod
A method is, or will be, using or used by more features of another class than the class on which it is defined. %reate a ne- method -ith a simi$ar body in the c$ass it uses most0 "ither turn the o$d method into a simp$e de$egation, or remo(e it a$together0
3o(e 4ie$d
A field is, or will be, used by another class more than the class on which it is defined. %reate a ne- fie$d in the target c$ass, and change a$$ its users0