Adriano Andrade
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## Trabalho da disciplina <b>Tópicos Especiais em Desenvolvimento de Software</b> ## Projetos em C# e Java <p> <b>Nome: Adriano Andrade<br> 6° Periodo </b> </p> # **Code Smells** <font size = "4"><b>1° problema: código dublicado</b></font> <p> &nbsp Linhas em vários métodos da classe repository com a mesma finalidade de busca passando data mínima e máxima. </p> ```csharp public async Task < List < SalesRecord >> FindByDateAsync(DateTime ? minDate, DateTime ? maxDate) { var result = from obj in _context.SalesRecord select obj; if (minDate.HasValue) { result = result.Where(x => x.Date >= minDate.Value); } if (maxDate.HasValue) { result = result.Where(x => x.Date <= maxDate.Value); } return await result .Include(x => x.Seller) .Include(x => x.Seller.Department) .OrderByDescending(x => x.Date) .ToListAsync(); } public async Task < List < IGrouping < Department, SalesRecord >>> FindByDateGroupingAsync(DateTime ? minDate, DateTime ? maxDate) { var result = from obj in _context.SalesRecord select obj; if (minDate.HasValue) { result = result.Where(x => x.Date >= minDate.Value); } if (maxDate.HasValue) { result = result.Where(x => x.Date <= maxDate.Value); } return await result .Include(x => x.Seller) .Include(x => x.Seller.Department) .OrderByDescending(x => x.Date) .GroupBy(x => x.Seller.Department) .ToListAsync(); } ``` <font size = "4"><b>Solução: extração de métodos</b></font> <p> &nbsp Foi aplicado a <b>extração de métodos</b> na classe repository onde havia repetição de linhas em vários métodos. </p> ```csharp public async Task < List < SalesRecord >> FindByDateAsync(DateTime ? minDate, DateTime ? maxDate) { var result = from obj in _context.SalesRecord select obj; result = GetMinMaxDate(minDate, maxDate, result); return await result .Include(x => x.Seller) .Include(x => x.Seller.Department) .OrderByDescending(x => x.Date) .ToListAsync(); } public async Task < List < IGrouping < Department, SalesRecord >>> FindByDateGroupingAsync(DateTime ? minDate, DateTime ? maxDate) { var result = from obj in _context.SalesRecord select obj; result = GetMinMaxDate(minDate, maxDate, result); return await result .Include(x => x.Seller) .Include(x => x.Seller.Department) .OrderByDescending(x => x.Date) .GroupBy(x => x.Seller.Department) .ToListAsync(); } ``` <font size = "4"><b>método extraido </b></font> ```csharp private static IQueryable < SalesRecord > GetMinMaxDate(DateTime ? minDate, DateTime ? maxDate, IQueryable < SalesRecord > result) { if (minDate.HasValue) result = result.Where(x => x.Date >= minDate.Value); if (maxDate.HasValue) result = result.Where(x => x.Date <= maxDate.Value); return result; } ``` <font size = "4"><b>2° problema: feature envy</b></font> <p> &nbsp Veja como o cliente acessa os dados da agenda para formatar a consulta, </p> ```java public class Cliente { private Agenda agenda; public String getAgenda() { return agenda.getNome() + " - " + agenda.getTelefone() + " - " + agenda.getEmail(); } } public class Agenda { public String nome; public String telefone; public String email; public Agenda(String nome, String telefone, String email) { this.nome = nome; this.telefone = telefone; this.email = email; } public String getNome() { return nome; } public String getTelefone() { return telefone; } public String getEmail() { return email; } } ``` <font size = "4"><b>Solução: extract method </b></font> <p> &nbsp Foi feita extração do método criando agendaFormatada() na classe da agenda para formatação.</p> ```java public class Agenda { public String nome; public String telefone; public String email; public Agenda(String nome, String telefone, String email) { this.nome = nome; this.telefone = telefone; this.email = email; } public String getNome() { return nome; } public String getTelefone() { return telefone; } public String getEmail() { return email; } public String agendaFormatada() { return getNome() + " - " + getTelefone() + " - " + getEmail(); } } public class Cliente { private Agenda agenda; public String getAgendaContatos() { return agenda.agendaFormatada(); } } ``` <font size = "4"><b> 3° problema: variável inútil </b></font> ```csharp public void InformarQuantidade(int quantidade, double valor) { int Quantidade = quantidade; ValorTotalItem = valor * Quantidade; } ``` <font size = "4"><b>Solução: apagar a variável</b></font> <p> &nbsp Foi aplicada a refatação, pois foi declarada uma variável que é obsoleta no método. </p> ```csharp public void InformarQuantidade(int quantidade, double valor) { ValorTotalItem = valor * quantidade; } ``` <font size = "4"><b>4° problema: comentário inútil </b></font> <p> &nbsp Comentários desnecessários no código deve ser retirado, neste exemplo foi feito um comentário para dizer que a seção contia atributos. </p> ```csharp public class Serie { // Atributos private Genero Genero { get; set; } private string Titulo { get; set; } private string Descricao { get; set; } private int Ano { get; set; } private bool Excluido { get; set; } } ``` <font size = "4"><b>Solução: retirar comentário</b></font> ```csharp public class Serie { private Genero Genero { get; set; } private string Titulo { get; set; } private string Descricao { get; set; } private int Ano { get; set; } private bool Excluido { get; set; } } ``` # **Débito Técnico** <font size = "4"><b>1° problema: nome fora do padrão.</b></font> <p> &nbsp Nome fora do padrão na interface. </p> ```csharp namespace WebApiDesafioFinal.Contracts { public interface IGeralPersist { void Add < T > (T entity) where T: class; void Update < T > (T entity) where T: class; void Delete < T > (T entity) where T: class; Task < bool > SaveChangesAsync(); } } ``` <font size = "4"><b>Solução: renomeação da interface</b></font> <p> &nbsp Realizei a renomeação do nome da interface IgeralPersist para IEntityPersist. </p> ```csharp namespace WebApiDesafioFinal.Contracts { public interface IEntityPersist { void Add < T > (T entity) where T: class; void Update < T > (T entity) where T: class; void Delete < T > (T entity) where T: class; Task < bool > SaveChangesAsync(); } } ``` <font size = "4"><b>2° problema: atributos fora do contexto </b></font> <p> Na classe escola havia também atributos referentes a aluno. </p> ```csharp public class Escola { private string nome { get; set; } private string endereco { get; set; } private string cnpj { get; set; } private Date dataFundacao { get; set; } private string nomeAluno { get; set; } private string matricula { get; set; } private int classe { get; set; } private Date dataAniversario { get; set; } private string cpf { get; set; } } ``` <font size = "4"><b>Solução: extração de classes</b></font> <P> &nbsp Foi criada uma nova classe aluno para receber esses atributos. </P> ```csharp public class Escola { private string nome { get; set; } private string endereco { get; set; } private string cnpj { get; set; } private Date dataFundacao { get; set; } public List<Aluno> Alunos = new List<Aluno>(); } public class Aluno { private string nome { get; set; } private string matricula { get; set; } private string nomeEscola { get; set; } private int classe { get; set; } private Date dataAniversario { get; set; } private string cpf { get; set; } } ``` <font size = "4"><b>3° problema: ausência de testes </b></font> <p> Ausência de testes da classe BuscarProduto </p> ```java @Service public class BuscarProduto implements BuscarProdutoService { @Autowired private ProdutoRepository repository; public BuscarProduto(ProdutoRepository repository) { this.repository = repository; } public Produto buscarProdutoId(long id) { return repository.findById(id).orElseThrow( () -> new IllegalArgumentException("Id not found" + id)); } public List<Produto> buscarProdutos() { return (repository.findAll().isEmpty()) ? Collections.emptyList() : repository.findAll(); } } ``` <font size = "4"><b>Solução: foi aplicado os testes </b></font> ```java public class BuscarProdutoTest { private static BuscarProdutoService buscarProdutoService; @BeforeAll public static void init() { buscarProdutoService = mock(BuscarProdutoService.class); Mockito.when(buscarProdutoService.buscarProdutoId(Mockito.anyInt())).thenReturn(ProdutoCONST.NULL); Mockito.when(buscarProdutoService.buscarProdutoId(10)).thenReturn(ProdutoCONST.GELADEIRA); } @Test public void testBuscarProdutoId() { Produto produto = buscarProdutoService.buscarProdutoId(10); assert produto != null; assert produto.getId() == 10; assert produto.getDescricao().equals("Geladeira"); assert produto.getValor() == 1500.00; assert produto.getQuantidade() == 2000; } @Test public void testBuscarProdutoIdNull() { Produto produto = buscarProdutoService.buscarProdutoId(Mockito.anyInt()); assert produto == null; } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully